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> ...
随机推荐
- PR 审批界面增加显示项方法
PR 审批界面增加显示项 解决方法 Step 1: 进入审批界面: Step 2: 在上图中,点击左下角'About this Page'查看数据源 点击上图中'Expand ...
- 漫谈程序员(十)大白菜装机版安装win7系统使用教程
大白菜装机版安装win7系统使用教程 安装win7系统准备工作: ①使用大白菜装机版,制作一个大白菜u盘启动盘 ②将下载好的ghost win7系统镜像包放入制作好的大白菜u盘启动盘中. ③更改电脑硬 ...
- Github Coding Developer Book For LiuGuiLinAndroid
Github Coding Developer Book For LiuGuiLinAndroid 收集了这么多开源的PDF,也许会帮到一些人,现在里面的书籍还不是很多,我也在一点点的上传,才上传不到 ...
- GitHub前50名的Objective-C动画相关库相关推荐,请自行研究
GitHub的Objective-C的动画UI库其实是最多的一部分,GitHub有相当一部分的动画大牛,如Jonathan George,Nick Lockwood,Kevin,Roman Efimo ...
- Oracle E-Business Suite Release 12.2 Information Center - Manage
Oracle E-Business Suite Maintenance Guide Release 12.2 Part No. E22954-14 PDF: http://docs.oracl ...
- Struts源码之OgnlValueStack
public class OgnlValueStack implements Serializable, ValueStack, ClearableValueStack, MemberAccessVa ...
- Google官方网络框架-Volley的使用解析Json以及加载网络图片方法
Google官方网络框架-Volley的使用解析Json以及加载网络图片方法 Volley是什么? Google I/O 大会上,Google 推出 Volley的一个网络框架 Volley适合什么场 ...
- android 实现淘宝收益图的折线
实现的效果我一会贴上,我先说下原理,我们知道要实现在canvas上画线,不就是要搞一个paint嘛,然后首先肯定要设置下paint的属性,那么画文字呢,不就是Textpaint吗, 对,就是这么简单, ...
- C#实现MD5算法
using UnityEngine; using System.Collections; using System.Security.Cryptography; public class GetMD5 ...
- leetcode之旅(6)-Add Digits
题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...