PAT1116: Come on! Let's C
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? 思路 简单的逻辑题,记录下选手排名和是否已经给过奖品就行。注意没在排行榜上的id多次查询后还是输出"Are you kidding?"而不是"Checked"。 代码
#include<iostream>
#include<cstdio>
#include<map>
#include<math.h>
#include<vector>
using namespace std; bool isPrime(const int num)
{
if(num == )
return true;
if(num % == )
return false;
for(int i = ;i < num;i++)
{
if(num % i == )
return false;
}
return true;
} int main()
{
int N;
while(cin >> N)
{
map<int,bool> dic;
vector<int> rankList();
for(int i = ;i <= N;i++)
{
int number;
cin >> number;
dic.insert(pair<int,bool>(number,false));
rankList[number] = i ;
}
int K;
cin >> K;
for(int i = ;i <K;i++)
{
int query;
cin >> query;
printf("%04d",query);
if(dic.count(query) <= )
{
cout << ": Are you kidding?" << endl;
continue;
}
if(dic[query])
{
cout << ": Checked" << endl;
continue;
} if(rankList[query] == )
{
dic[query] = true;
cout << ": Mystery Award" << endl;
}
else if(isPrime(rankList[query]))
{
dic[query] = true;
cout << ": Minion" << endl;
}
else
{
dic[query] = true;
cout << ": Chocolate" << endl;
}
}
}
}
PAT1116: Come on! Let's C的更多相关文章
- PAT1116. Come on! Let's C (map)
思路:模拟一下就好了,map用来记录每个人的排名. AC代码 #include <stdio.h> #include <map> #include <math.h> ...
随机推荐
- Android群英传笔记——第六章:Android绘图机制与处理技巧
Android群英传笔记--第六章:Android绘图机制与处理技巧 一直在情调,时间都是可以自己调节的,不然世界上哪有这么多牛X的人 今天就开始读第六章了,算日子也刚好一个月了,一个月就读一半,这效 ...
- Android Activity的四种经典传值方法
文/ http://blog.csdn.net/sk719887916/article/details/41723613 skay 开发中遇到多个activity的传值问题 相邻两个之间的传值 或者 ...
- Android实现RecyclerView侧滑删除和长按拖拽-ItemTouchHelper
RecyclerView这个被誉为ListView和GirdView的替代品,它的用法在之前的一篇博文中就已经讲过了,今天我们就来实现RecyclerView的侧滑删除和长按拖拽功能,实现这两个功能我 ...
- EBS 系统标准职责定义MAP
ERP的相关职责 Responsibility Name(职责) Application(应用) Responsibility Key(关键字) Data Group(数据组) M ...
- 避免"Physics Space Locked"错误
在一些cocos2d中使用物理引擎的代码中,往往会出现如下错误: Aborting due to Chipmunk error: You cannot manually reindex objects ...
- Linux其他常见压缩备份工具 - dd,cpio
dd dd 可以读取磁碟装置的内容(几乎是直接读取磁区"sector"),然后将整个装置备份成一个文件呢!真的是相当的好用啊- dd 的用途有很多啦-但是我们仅讲一些比较重要的选项 ...
- Hbase节点管理
1.退役节点 (1) shell>balance_switch false 然后,hbase-daemon.sh stop regionserver (2) graceful_stop.sh U ...
- 采用UltraISO制作U盘启动盘
采用UltraISO制作U盘启动盘 打开UltralSO,选择"文件"--->"打开",如下图: 图1 打开WIN7操作系统的ISO文件,如下图: 图2 ...
- 单片机PWM调制技术
我们可以看看下图,下图就是一个典型的PWM的波形图. T是一个周期,T1就是高电平所占用的时间,T2就是低电平所占用的时间. 如上图所示T1为脉冲宽度(就是导通时间),周期为T,则输出电压的平均值为U ...
- 恶补web之八:jQuery(1)
jquery是一个js库,极大的简化了js编程.jquery是一个写的更少,但做的更多的轻量级js库. jquery位于一个js文件中,其中包含了所有jquery函数,可以用如下标记把jquery添加 ...