一、题目描述
Input Specification:
Output Specification:
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?
二、解题思路
题目给的ID为四位数字,我们可以用一个数组表示每个ID对应的排名,不存在则设为0,写一个判断素数的函数checkPrime,接着对每个输入的query进行判断输出即可。详情见代码注释。
三、AC代码
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
const int maxn = 10010;
int ranks[maxn] = {0}; //存放每个ID对应的排名
bool checked[maxn]; //标记是否已经检查过
bool checkPrime(int n) //判断是否为素数
{
for(int i=2; i*i<=n; i++)
{
if(n%i == 0) return false;
}
return true;
}
int main()
{
int N, K, tmp;
scanf("%d", &N);
for(int i=1; i<=N; i++)
{
scanf("%d", &tmp);
ranks[tmp] = i; //存入排名
}
scanf("%d", &K);
fill(checked, checked+maxn, false);
for(int i=0; i<K; i++)
{
scanf("%d", &tmp);
printf("%04d: ", tmp);
if(checked[tmp]) //如果已经查过,则打印Checked
{
printf("Checked\n");
continue;
}
if(ranks[tmp] == 0) //不存在查询的ID
{
printf("Are you kidding?\n");
continue;
}
//对应输出
if(ranks[tmp] == 1) printf("Mystery Award\n");
else if(checkPrime(ranks[tmp])) printf("Minion\n");
else printf("Chocolate\n");
checked[tmp] = true; //设为已查询
}
return 0;
}