PAT_A1116#Come on! Let's C
Source:
Description:
"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 (≤), 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 isMystery Award
, orMinion
, orChocolate
. If the ID is not in the ranklist, printAre you kidding?
instead. If the ID has been checked before, printID: 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?
Keys:
- 素数(Prime)
Attention:
- 对于较大规模的数据,采用打表的方法可以大大的优化时间,平时应该养成习惯已备不时之需;
Code:
/*
Data: 2019-06-11 20:19:43
Problem: PAT_A1116#Come on! Let's C
AC: 15:40 题目大意:
按排名给出N名同学的ID,
第一名,Mystery Award
素数名次,Minion
其他名次,Chocolate
询问过了,Checked
占便宜者,Are you kidding?
*/ #include<cstdio>
#include<string>
#include<vector>
#include<iostream>
using namespace std;
const int M=1e5;
int isPrime[M],n,name;
string id[M];
vector<int> prime; void Euler()
{
fill(isPrime,isPrime+n+,);
isPrime[]=;isPrime[]=;
for(int i=; i<=n; i++){
if(isPrime[i])
prime.push_back(i);
for(int j=; j<prime.size(); j++){
if(i*prime[j]>n)
break;
isPrime[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif scanf("%d", &n);
Euler();
for(int i=; i<=n; i++)
{
scanf("%d", &name);
if(i == )
id[name] = "Mystery Award";
else if(isPrime[i])
id[name] = "Minion";
else
id[name] = "Chocolate";
}
scanf("%d", &n);
for(int i=; i<n; i++)
{
scanf("%d", &name);
printf("%04d: ", name);
if(id[name].size() != ){
cout << id[name] << endl;
id[name] = "Checked";
}
else
cout << "Are you kidding?" << endl;
} return ;
}
PAT_A1116#Come on! Let's C的更多相关文章
随机推荐
- double x = 10 ,y = 0;y = x % 2; 这个表达式正确吗?
The remainder function and % operator. 以下这段代码过不了编译的(gcc) #include <stdio.h> #include <fenv. ...
- [字典树] poj 2418 Hardwood Species
题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS Memory ...
- jQuery - 点击图片加边框
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 浅析 Linux 中的时间编程和实现原理一—— Linux 应用层的时间编程【转】
本文转载自:http://www.cnblogs.com/qingchen1984/p/7007631.html 本篇文章主要介绍了"浅析 Linux 中的时间编程和实现原理一—— Linu ...
- codeforce1046 Bubble Cup 11 - Finals 题解
比赛的时候开G开了3h结果rose说一句那唯一一个AC的是羊的心态就崩了.. 这套题感觉质量挺好然后就back了下 A: AI robots 有三个限制条件:相互能够看见和智商的差.使用主席树,可以维 ...
- HDU 3887 Counting Offspring(DFS序+树状数组)
Counting Offspring Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- iOS开发之判断手机号和邮箱 正则表达式
#pragma mark --判断手机号合法性 + (BOOL)checkPhone:(NSString *)phoneNumber { NSString *regex = @"^((13[ ...
- SQLServer2008 在where条件中使用CASE WHEN
create table #temp( id int identity(1,1), name varchar(20), startYear int, startMonth in ...
- JavaScript Array 整理 - 元素操作
整理一下Array对象中针对元素操作的方法. 分别是: concat (组合数组) join(数组转字符串) pop(删除最后一个元素) shift(删除第一个元素) push(在数组尾部添加新元素) ...
- Android Retrofit 2.0文件上传
Android Retrofit 实现(图文上传)文字(参数)和多张图片一起上传 使用Retrofit进行文件上传,肯定离不开Part & PartMap. public interface ...