题目描述 链接 素数判断+map存储 代码 #includebits/stdc++.husing namespace std;int n,k;mapstring, string mp;mapstring, bool check;bool is_prime(int n){ if(n 2) return false; for(int i=2; i=sqrt(n); i++){ if(n % i == 0) return fa
题目描述
链接
素数判断+map存储
代码
#include<bits/stdc++.h> using namespace std; int n,k; map<string, string> mp; map<string, bool> check; bool is_prime(int n){ if(n < 2) return false; for(int i=2; i<=sqrt(n); i++){ if(n % i == 0) return false; } return true; } int main(){ cin>>n; string s; for(int i=1;i<=n;i++){ cin>>s; if(i==1) mp[s] = "Mystery Award"; else if(is_prime(i)){ mp[s] = "Minion"; }else{ mp[s] = "Chocolate"; } } cin>>k; while(k--){ cin>>s; if(mp.find(s) == mp.end()){ cout<<s<<": Are you kidding?"<<endl; }else if(check[s] == false){ check[s] = true; cout<<s<<": "<<mp[s]<<endl; }else{ cout<<s<<": Checked"<<endl; } } }