题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805269828059136
题解:
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 10000 + 5; 4 5 struct Temp { 6 bool value; 7 bool visited; 8 int num; 9 }; 10 11 void Inite(Temp t[]) { 12 for (int i = 0; i < maxn; i++) { 13 t[i].num = 0; 14 t[i].value = false; 15 t[i].visited = false; 16 } 17 } 18 19 bool is_prime(int n) { 20 if (n < 2) return false; 21 for (int i = 2; i <= sqrt(n); i++) { 22 if (n%i == 0) return false; 23 } 24 return true; 25 } 26 27 int main() { 28 int n, temp, k, cnt = 2; 29 cin >> n; 30 Temp t[maxn]; 31 Inite(t); 32 bool flag = false; 33 for (int i = 0; i < n; i++) { 34 cin >> temp; 35 if (!flag) { 36 t[temp].value = true; 37 t[temp].num = 1; 38 flag = true; 39 } 40 else { 41 t[temp].value = true; 42 t[temp].num = cnt++; 43 } 44 } 45 cin >> k; 46 while (k--) { 47 cin >> temp; 48 if (t[temp].value) { 49 if (t[temp].visited == true) { 50 cout << setw(4) << setfill('0') << temp << ": " << "Checked" << endl; 51 } 52 else { 53 if (t[temp].num == 1) { 54 cout << setw(4) << setfill('0') << temp << ": " << "Mystery Award" << endl; 55 t[temp].visited = true; 56 } 57 else if (is_prime(t[temp].num)) { 58 cout << setw(4) << setfill('0') << temp << ": " << "Minion" << endl; 59 t[temp].visited = true; 60 } 61 else { 62 cout << setw(4) << setfill('0') << temp << ": " << "Chocolate" << endl; 63 t[temp].visited = true; 64 } 65 } 66 } 67 else 68 cout << setw(4) << setfill('0') << temp << ": " << "Are you kidding?" << endl; 69 } 70 return 0; 71 }
4757

被折叠的 条评论
为什么被折叠?



