Given the final ranklist and a sequence of contestant ID‘s, you are supposed to tell the corresponding awards.
Each input file contains one test case. For each case, the first line gives a positive integer N (≤), the total number of contestants. Then N lines of the ranklist follow, each in order gives a contestant‘s ID (a 4-digit number). After the ranklist, there is a positive integer K followed by K query ID‘s.
For each query, print in a line ID: award where the award is Mystery Award, or Minion, or Chocolate. If the ID is not in the ranklist, print Are you kidding? instead. If the ID has been checked before, print ID: Checked.
6 1111 6666 8888 1234 5555 0001 6 8888 0001 1111 2222 8888 2222
8888: Minion 0001: Chocolate 1111: Mystery Award 2222: Are you kidding? 8888: Checked 2222: Are you kidding?
【AC steps】:1、[ 确定第一 ] 2、[ 判断素数 ] 3、[ 分类输出 ]
 
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 bool isPrime(int x) 5 { 6 if(x < 2) return false; 7 for(int i = 2; i*i <= x; i++) 8 if(x%i==0) return false; 9 return true; 10 } 11 12 int main() 13 { 14 map<string, int> m, mm; 15 int n; cin >> n; 16 for(int i = 1; i <= n; i++) 17 { 18 string s; cin >> s; 19 m[s] = i; 20 } 21 cin >> n; 22 for(int i = 1; i <= n; i++) 23 { 24 string s; cin >> s; 25 if(m[s]) 26 { 27 if(!mm[s]) 28 { 29 mm[s] = 1; 30 if(m[s] == 1) cout << s << ": Mystery Award" << endl; 31 else if(isPrime(m[s])) cout << s << ": Minion" << endl; 32 else cout << s << ": Chocolate" << endl; 33 } 34 else cout << s << ": Checked" << endl; 35 } 36 else cout << s << ": Are you kidding?" << endl; 37 } 38 return 0; 39 }
PAT 甲级 1116 Come on! Let's C (20分)
原文:https://www.cnblogs.com/kamisamalz/p/13586939.html