PAT A1116 Come on! Let's C [素数+STL模拟]
发布时间:2020-12-16 09:17:28 所属栏目:百科 来源:网络整理
导读:题目描述 链接 素数判断+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 false; } return t
题目描述链接 代码#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; } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |