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> ...
随机推荐
- Memcached学习笔记 — 第四部分:Memcached Java 客户端-gwhalin(1)-介绍及使用
介绍 Memcached java client是官方推荐的最早的memcached java客户端.最新版本:java_memcached-release_2.6.1. 官方下载地址:http ...
- Java-ServletRequestEvent-ServletRequestAttributeEvent
/** * Events of this kind indicate lifecycle * events for a ServletRequest. * The source of the even ...
- Java-ServletInputStream
import java.io.InputStream; import java.io.IOException; /** * Provides an input stream for reading b ...
- linux - 目录、文件默认属性: umask使用
一 权限掩码umask umask是chmod配套的,总共为4位(gid/uid,属主,组权,其它用户的权限),不过通常用到的是后3个,例如你用chmod 755 file(此时这文件的权限是属主读( ...
- 【57】android图片印刻,阳刻,素描图效果处理
介绍我参与开发的妙趣剪纸app使用的图片处理相关的技术 关于妙趣剪纸,各大android商店都可以下载,下面贴出小米商店的链接 妙趣剪纸下载 软件效果截图 如何实现上面的图片处理效果呢 1.初始化高斯 ...
- linux内核算法---hex_to_bin分享
这是我从内核抠出来的一段代码,用处就是传入一个字符,即可以用printf语句%d以十进制数的格式输出,同时也可以以%p地址的形式输出. 代码如下: #include <stdio.h> # ...
- iOS和Android开发异同点(一)
说到移动开发,目前主流平台有谷歌的android os 系统,苹果iOS系统,和微软主打的windows Phone OS 系统,至于目前为啥移动开发中,安卓和iOS比较受欢迎,者要看三家产品的历史由 ...
- Android Hal层简要分析
Android Hal层简要分析 Android Hal层(即 Hardware Abstraction Layer)是Google开发的Android系统里上层应用对底层硬件操作屏蔽的一个软件层次, ...
- java--加强之 jdk1.5简单新特性,枚举,注解
转载请申明出处:http://blog.csdn.net/xmxkf/article/details/9944041 Jdk1.51新特性(静态导入,可变参数,加强for循环,自动拆装箱) 08.ja ...
- 关于C语言程序条件编译的简单使用方法
#include <stdio.h> #include <stdlib.h> #define Mode //如果定义了Mode,那么就执行这个函数 #ifdef Mode vo ...