原文:我的个人博客
原题链接
思路
题目已经按名次给定每个同学ID。用map<string,int>m
来存储每个同学获得的称号。第一名表示为1,排名为素数排名的记为2,其余的记为3.并在查询的过程中,将已经查询的记为4.当然没有出现的ID默认值即为0.
代码
#include <bits/stdc++.h>
using namespace std;
int isPrime(int x){
if(x<=0) return 0;
for(int i=2;i<=sqrt(x);i++){
if(x%i==0) return 0;
}
return 1;
}
int main(){
int n,k;
string tmp;
map<string,int>m;
cin>>n;
for(int i=1;i<=n;i++){
cin>>tmp;
if(i==1) m[tmp] = 1;//Mystery Award
else if(isPrime(i)) m[tmp] = 2;//Minion
else m[tmp] = 3;//Chocolate
}
cin>>k;
for(int i=0;i<k;i++){
cin>>tmp;
cout<<tmp<<": ";
if(m[tmp]==1){
cout<<"Mystery Award"<<endl;
m[tmp] = 4;//checked
}else if(m[tmp] == 2){
cout<<"Minion"<<endl;
m[tmp] = 4;
}else if(m[tmp]==3){
cout<<"Chocolate"<<endl;
m[tmp] = 4;
}else if(m[tmp]==4){
cout<<"Checked"<<endl;
}else{
cout<<"Are you kidding?"<<endl;
}
}
}