PAT (Advanced Level) Practice 1116 Come on! Let‘s C (20 分) 凌宸1642

PAT (Advanced Level) Practice 1116 Come on! Let’s C (20 分) 凌宸1642

题目描述:

“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.

译:“Let’s C”是由浙江大学计算机科学与技术学院主办的一项流行且有趣的编程竞赛。 由于比赛的想法是为了好玩,奖励规则如下:

  • 0、 冠军将获得“神秘奖”(如学生研究论文的大合集……)。

  • 1、 排名第一的将获得最佳奖——小黄人!

  • 2、 其他人都会收到巧克力。

给定最终的排名列表和一系列参赛者 ID,您应该说出相应的奖项。


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.

译:每个输入文件包含一个测试用例。 对于每种情况,第一行给出一个正整数 N(≤104),即参赛者的总数。 然后是排名表的 N 行,每行依次给出一个参赛者的 ID(一个 4 位数字)。 在 ranklist 之后,有一个正整数 K,后跟 K 个查询 ID。


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.

译:对于每个查询,打印一行 ID: award,其中奖励是Mystery Award,、MinionChocolate。 如果 ID 不在 ranklist 中,请打印 Are you kidding? 。 如果之前已检查过 ID,请打印 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?

The Idea:

  • 先建立一个 ID 到 rank 的映射,然后再查询的时候,先判断是否有这个 ID ,如果有的话,那就在判断是否已经检查过了; 如果没有检查,再判断排名属于哪一种,输出对应的奖励即可。
  • 素数可以利用筛法。

The Codes:

#include<bits/stdc++.h>
using namespace std ;
const int maxn = 10010 ;
map<int , int > mp ;  // id -> rank 的映射 
bool isChecked[maxn] ;  // 某 rank 是否检查过 
vector<bool> prime(maxn , true) ;  // 某 rank 是否为素数 
int n , t , k , q ;
void init(){
	for(int i = 2 ; i * i < maxn ; i ++){
		for(int j = 2 ; j * i < maxn ; j ++){
			prime[i * j] = false ;
		}
	}
}
int main(){
	init() ;
	cin >> n ;
	for(int i = 1 ; i <= n ; i ++){
		cin >> t ;
		mp[t] = i ;
	}
	cin >> k ;
	while(k --){
		cin >> q ; 
		if(mp.count(q) == 0) printf("%04d: Are you kidding?\n" , q) ;	// 不合法 ID 
		else{
			if(isChecked[mp[q]]) printf("%04d: Checked\n" , q) ; 		// 已检查 ID 
			else{
				if(mp[q] == 1) printf("%04d: Mystery Award\n" , q) ; 	// 冠军
				else if(prime[mp[q]])  printf("%04d: Minion\n" , q) ; 	// rank 为素数
				else  printf("%04d: Chocolate\n" , q) ;      			// 其他 rank 
			}
			isChecked[mp[q]] = true ; 
		}
	}
	return 0 ;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lingchen0522

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值