星空's Blog
星空's Blog
PAT-A1116 Come on! Let's C

原题

Come on! Let’s C (20 分)

题解

没啥好说的,基本操作

代码

#include <iostream>
#include <map>
#include <set>
using namespace std;

bool isPrime(int n) {
    for (int i = 2;i < n;i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main(void) {
    map<string,int> ranks;
    set<string> ids;
    int n;
    cin >> n;
    for (int i = 1;i <= n;i++) {
        string id;
        cin >> id;
        ranks[id] = i;
    }
    int k;
    cin >> k;
    for (int i = 0;i < k;i++) {
        string query;
        cin >> query;
        if (ids.count(query)) {
            cout << query << ": Checked" << endl;
        } else {
            if (ranks.count(query)) {
                int rank = ranks[query];
                if (rank == 1) {
                    cout << query << ": Mystery Award" << endl;
                } else if (isPrime(rank)) {
                    cout << query << ": Minion" << endl;
                } else {
                    cout << query << ": Chocolate" << endl;
                }
                ids.insert(query);
            } else {
                cout << query << ": Are you kidding?" << endl;
            }
        }
    }
    return 0;
}
所有文章禁止转载。
代码仅供参考
为了对抗广告机器人,首次留言将会被审核
首页      算法学习      PAT-A      PAT-A1116 Come on! Let's C
https://secure.gravatar.com/avatar/271861a23dcdde929d3ee8cb8c04f854?s=256&d=monsterid&r=g

星空

文章作者

发表评论

textsms
account_circle
email

星空's Blog

PAT-A1116 Come on! Let's C
原题 Come on! Let's C (20 分) 题解 没啥好说的,基本操作 代码 #include <iostream> #include <map> #include <set> using namespace std; bool isPrime(int n) { …
扫描二维码继续阅读
2019-09-01
分类
标签云