1116. Come on! Let’s C (20)
“Let’s C” is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as the following:
- The Champion will receive a “Mystery Award” (such as a BIG collection of students’ research papers…).
- Those who ranked as a prime number will receive the best award – the Minions (小黄人)!
- Everyone else will receive chocolates.
Given the final ranklist and a sequence of contestant ID’s, you are supposed to tell the corresponding awards.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<=10000), 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.
Output Specification:
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”.
Sample Input:
6
1111
6666
8888
1234
5555
0001
6
8888
0001
1111
2222
8888
2222
Sample Output:
8888: Minion
0001: Chocolate
1111: Mystery Award
2222: Are you kidding?
8888: Checked
2222: Are you kidding?
结题思路 :
题意要求我们输出每个问询同学的对应的奖励。
要求1:质数(prime)判定;
要求2:对访问过的数据进行标记;
程序步骤:
第一步、保存数据,及对应的奖励标记;
第二步、输出问询的结果,并将有记录的同学标记取负。
具体程序(AC)如下:
#include <iostream>
#include <map>
using namespace std;
map<string,int> listRank;
bool isPrime(int no)//质数判定
{
for(int i = 2; i * i <= no; ++i)
if(no % i)
continue;
else
return 0;
return 1;
}
int main()
{
int n;
cin>>n;
string no;
listRank.clear();
if(n)
{
cin>>no;
listRank[no] = 1;//1标记为第一名
for(int i = 2; i <= n; ++i)
{
cin>>no;
if(isPrime(i))
listRank[no] = 2;//标记为质数
else
listRank[no] = 3;//标记为其他情况
}
}
cin>>n;
for(int i = 0; i < n; ++i)
{
cin>>no;
auto iterate = listRank.find(no);
if(iterate==listRank.end())
cout<<no<<": Are you kidding?"<<endl;
else
{
if(iterate->second > 0)//标记为正才允许访问
{
if(iterate->second == 1)
cout<<no<<": Mystery Award"<<endl;
else if(iterate->second == 2)
cout<<no<<": Minion"<<endl;
else
cout<<no<<": Chocolate"<<endl;
listRank[no] = - iterate->second;//标记取负
}
else
cout<<no<<": Checked"<<endl;
}
}
return 0;
}