您的位置:首页 > 其它

1116. Come on! Let’s C (20)-PAT甲级真题

2016-09-11 17:46 519 查看
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:

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 (<=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?

分析:ran数组标记每个id对应的排名,集合ss存储所有已经询问过的id,如果发现当前id已经出现在ss中,则输出“Checked”,如果ran[id] == 0说明当前id不在排名列表中,所以输出“Are you kidding?”,如果ran[id]为1则输出“Minion”,如果ran[id]为素数则输出“Mystery Award”,否则输出“Chocolate”

#include <cstdio>
#include <set>
#include <cmath>
using namespace std;
int ran[10000];
bool isprime(int a) {
if(a <= 1) return false;
int Sqrt = sqrt((double)a);
for(int i = 2; i <= Sqrt; i++) {
if(a % i == 0)
return false;
}
return true;
}
int main() {
int n, k;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
int id;
scanf("%d", &id);
ran[id] = i + 1;
}
scanf("%d", &k);
set<int> ss;
for(int i = 0; i < k; i++) {
int id;
scanf("%d", &id);
printf("%04d: ", id);
if(ran[id] == 0) {
printf("Are you kidding?\n");
continue;
}
if(ss.find(id) == ss.end()) {
ss.insert(id);
} else {
printf("Checked\n");
continue;
}
if(ran[id] == 1) {
printf("Mystery Award\n");
}else if(isprime(ran[id])) {
printf("Minion\n");
}else {
printf("Chocolate\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: