"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:
- 0、 The Champion will receive a "Mystery Award" (such as a BIG collection of students' research papers...).
- 1、 Those who ranked as a prime number will receive the best award -- the Minions (小黄人)!
- 2、 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 (≤104), 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?
--------------------------------------这是题目和解题的分割线--------------------------------------
一道水题,如果是整型读入的话,记得输出格式得是%04d,不然无法保证0001这种样式的输出哈~
#include<cstdio>
#include<cmath>
using namespace std;
//素数判断
int isPrime(int n)
{
if(n<=1) return 0;
int sqr = int(sqrt(n*1.0)),i;
for(i=2;i<=sqr;i++)
if(n%i==0) return 0;
return 1;
}
int main()
{
int rank[10005] = {},n,q,i;
scanf("%d",&n);
//数据很小,直接用数组存排名就行
for(i=1;i<=n;i++)
{
int tmp;
scanf("%d",&tmp);
rank[tmp] = i;
}
scanf("%d",&q);
for(i=0;i<q;i++)
{
int tmp;
scanf("%d",&tmp);
if(rank[tmp]==10005)
printf("%04d: Checked\n",tmp);
//这里把重复过和其余情况分开处理了
else
{
if(rank[tmp]==1)
printf("%04d: Mystery Award\n",tmp);
else if(isPrime(rank[tmp]))
printf("%04d: Minion\n",tmp);
else if(rank[tmp]==0)
printf("%04d: Are you kidding?\n",tmp);
else
printf("%04d: Chocolate\n",tmp);
//除了错误ID外,其余都标记为出现过
if(rank[tmp]!=0)
rank[tmp] = 10005;
}
}
return 0;
}