PTA2021 跨年挑战赛部分题解

7-1 压岁钱

不用说

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const ll inf = 2147483647;
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int sum = a + b + c + d;
    cout << sum;
    return 0;
}

 

7-2 射击成绩

微米转毫米按环判断。

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const ll inf = 2147483647;
using namespace std;

int main() {
    double n;
    cin >> n;
    if(n <= 11500 / 2)
        cout<<10;
    else if(n <= 27500 / 2)
        cout<<9;
    else if(n <= 43500 / 2)
        cout<<8;
    else if(n <= 59500 / 2)
        cout<<7;
    else if(n <= 75500 / 2)
        cout<<6;
    else if(n <= 91500 / 2)
        cout<<5;
    else if(n <= 107500 / 2)
        cout<<4;
    else if(n <= 123500 / 2)
        cout<<3;
    else if(n <= 139500 / 2)
        cout<<2;
    else if(n <= 155500 / 2)
        cout<<1;
    else cout<<0;
    return 0;
}

 

7-3 Cassels方程

不用说

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const ll inf = 2147483647;
using namespace std;

int main() {
    int n;
    cin >> n;
    while (n--) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x * x + y * y + z * z != 3 * x * y * z)
            cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

 

7-4 相生相克

根据题意相生相克的数字和判断,也可以直接从金到土的数字看另一个数字是啥判断相生还是相克,因为相生相克都是一对一的。

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const ll inf = 2147483647;
using namespace std;

void judeg(int a, int b) {
    int sum = a + b;
    if (sum == 3)
        cout << "1 ke 2\n";
    else if (sum == 7) {
        if (a == 2 || a == 5)
            cout << "2 ke 5\n";
        else cout << "3 ke 4\n";
    } else if (sum == 8)
        cout << "5 ke 3\n";
    else if (sum == 5) {
        if (a == 4 || a == 1)
            cout << "4 ke 1\n";
        else cout << "3 sheng 2\n";
    } else if (sum == 6) {
        if (a == 2 || a == 4) {
            cout << "2 sheng 4\n";
        } else cout << "5 sheng 1\n";
    } else if (sum == 9)
        cout << "4 sheng 5\n";
    else if (a == 1 || a == 3)
        cout << "1 sheng 3\n";
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        int x, y;
        cin >> x >> y;
        judeg(x, y);
    }
    return 0;
}

 

7-5 7-6太菜了没过

 

7-5 整除阶乘

对于每个数,直接把n * n + 1对n!的各乘因子求余,最后判断n * n + 1是否变成1来输出结果,用f做是否有结果标记,如果没有就输出None。来自:csdn

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const ll inf = 2147483647;
using namespace std;

int main() {
    int n, m, f = 0;
    cin >> n >> m;
    for (int i = n; i <= m; i++) {
        int sum = i * i + 1;
        for (int j = 2; j <= i; j++) {
            if (sum >= j && sum % j == 0)
                sum /= j;
            else if (sum < j && j % sum == 0)
                sum = 1;
        }
        if (sum == 1) {
            cout << i << endl;
            f = 1;
        }
    }
    if (!f)cout << "None";
    return 0;
}

 

7-7 打PTA 

先判断最后一个字符是否是?,不是直接输出enen,是就从下标2开始判断此下标是否是字符A和前面两个字符是否是T和P,是的话就把flag f设为真,f默认为假,再根据f的真假输出结果。

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const ll inf = 2147483647;
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int j = 0; j < n; j++) {
        string s;
        if (j == 0)
            getchar();
        getline(cin, s);
        int t = s.length();
        int f = 0;
        if (s[t - 1] != '?') {
            cout << "enen\n";
        } else {
            for (int i = 2; i < t; i++) {
                if (s[i] == 'A' && s[i - 1] == 'T' && s[i - 2] == 'P') {
                    f = 1;
                    break;
                }
            }
            if (f)
                cout << "Yes!\n";
            else cout << "No.\n";
        }
    }
    return 0;
}

 

7-8 完美对称

从头到尾开始判断区间是否对称,不对称头就顺移到下一位直到找到对称区间,当头等于第一位时就直接完整输出,不是时倒序输出头前面区间。

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const ll inf = 2147483647;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    for (int i = 1; i <= n; i++) {
        int k = n, j = i, f = 1;
        while (k >= j) {//这里判断是否对称
            if (v[k] != v[j]) {
                f = 0;
                break;
            }
            k--;
            j++;
        }
        if (f && i != 1) {
            cout << v[i - 1];
            for (int p = i - 2; p >= 1; p--) {
                cout << ' ' << v[p];
            }
            break;
        } else if (f) {
            cout << v[1];
            for (int p = 2; p <= n; p++) {
                cout << ' ' << v[p];
            }
            break;
        }
    }
    return 0;
}

 

posted @ 2021-01-01 23:58  acwarming  阅读(881)  评论(0编辑  收藏  举报