1003我要通过!

#include<bits/stdc++.h>
using namespace std;
//1003我要通过!
int main() {
   
	string str;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
   
        cin >> str;
        int loc_p = -1, nump = 0, numt = 0, loc_t = -1, numa = 0;
		int left = 0, center  = 0, right = 0;
		int len = str.length();
		for(int i = 0; i < len; i++) {
   
			if(str[i] == 'P') {
   
				nump++;
				loc_p = i;
			} else if(str[i] == 'T') {
   
				numt++;
				loc_t = i;
			} else if(str[i] != 'A') {
   
				numa++;
			}
		}
		if(nump != 1 || numt != 1 || loc_t - loc_p <= 1 || numa > 0) {
   
			printf("NO\n");
			continue;
		}
		left = loc_p;
		center = loc_t - loc_p - 1;
		right = len - loc_t - 1;
		if(left * center == right) {
   
			printf("YES\n");
		} else {
   
			printf("NO\n");
		}
	}

	return 0;
}

1007素数对猜想


#include <bits/stdc++.h>
using namespace std;
//1007 素数对猜想
const int maxn = 100010;
bool judge[maxn]; //判断是否为合数
int pri[maxn], cnt = 0,ans=0;
void getprime(int n)
{
   
    for (int i = 2; i <= n; i++)
    {
   
        if (!judge[i])
            pri[cnt++] = i;
        for (int j = 0; j < cnt; j++)
        {
   
            if (i * pri[j] > n)
                break;
            judge[i * pri[j]] = 1; //标记合数
            if (i % pri[j] == 0)
                break;
        }
    }
}
int main()
{
   
    int n;
    cin >> n;
    getprime(100005);
    for (int i = 1;pri[i]<=n; i++)
    {
   
        if (pri[i] - pri[i - 1] == 2)
            ans++;
        }
    cout << ans;
    return 0;
}

1008 数组元素循环右移问题 (20 分)


#include<bits/stdc++.h>
using namespace std;
//1008 数组元素循环右移问题 (20 分)
int main(){
   
    ios::sync_with_stdio(0);
    int n, m;
    int a[105],b[105];
    cin >> n >> m;
    for (int i = 0; i < n;i++){
   
        cin >> a[i];
    }
    m %= n;
    int k = 0;
    for (int i = n-m; i < n;i++){
   
        b[k++] = a[i];
    }
    for (int i = 0; i < n - m;i++){
   
        b[k++] = a[i];
    }
    for (int i = 0; i < n;i++){
   
        if(i==n-1)
            cout << b[i];
        else
            cout << b[i] << " ";
    }
        return 0;
}

1009 说反话 (20 分)


#include<bits/stdc++.h>
using namespace std;
//1009 说反话 (20 分)
int main(){
   
    vector<string> s;
    string a;
    while(cin>>a){
   
        s.push_back(a);
    }
    for (int i = s.size() - 1;i>=0; i--)
    {
   
        if(i!=0)
            cout << s[i] << " ";
        else
            cout << s[i];
    }

        return 0;
}

1010 一元多项式求导 (25 分)

#include<bits/stdc++.h>
using namespace std;
//1010 一元多项式求导 (25 分)
int main(){
   
    ios::sync_with_stdio(0);
    int a, b;
    vector<pair<int, int>> s;
    int flag = 0;
    while(cin>>a>>b){
   
        if(b!=0){
   
            a = a * b;
            b -= 1;
            s.push_back({
   a, b});
            flag = 1;
        }
    }
    if(!flag)
        s.push_back({
   0,0});
    for (int i = 0; i < s.size();i++){
   
        if(i!=s.size()-1){
   
            cout << s[i].first << " " << s[i].second << " ";
        }
        else
            cout << s[i].first << " " << s[i].second;
    }
        return 0;
}
#include <iostream>
using namespace std;
int main() {
   
    int a, b, flag = 0;
    while (cin >> a >> b) {
   
        if (b != 0) {
   
            if (flag == 1) cout << " ";
            cout << a * b << " " << b - 1;
            flag = 1;
        }
    }
    if (flag == 0) cout << "0 0";
    return 0;
}