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> ...
随机推荐
- 【Matlab编程】Matlab及Java小时钟
一年前曾经用matlab的gui做了一个时钟,由于是直接用GUIDE和ActiveX控件写的,程序虽说有许多行,大多数都是自动生成的,自己写的只有十几行而已.闲着没事,就耗费了下午的时间用matlab ...
- 聊聊String
当我们最开始学习java的时候,老师会告诉我们字符串的比较需要用equals(); 真的是这样的吗? 我们看看下面的例子 public class TestString { public static ...
- "C#":MySql批量数量导入
现在对数据库(以MySql为例)的操作大多会封装成一个类,如下例所示: namespace TESTDATABASE { public enum DBStatusCode { ALL_OK, MySq ...
- 自动生成材质Material(Unity3D开发之十九)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/46854411 ...
- Spring--FileSystemXmlApplicationContext
//从文件系统或者统一定位资源中获得上下文的定义 public class FileSystemXmlApplicationContext extends AbstractXmlApplication ...
- iwms后台出现从客户端(ctl00$cphMain$logo="<img src="pic/logo.g...")中检测到有潜在危险的 Request.Form 值。错误解决方法
请将 web.config 文件中httpRuntime 配置节中的 requestValidationMode 特性设置为 requestValidationMode="2.0" ...
- MfgTool (i.MX53)使用
1 Introduction The MfgTool is a manufacturing tool from Freescale that runs under Windows. It is des ...
- LeetCode(55)- Palindrome Linked List
题目: Given a singly linked list, determine if it is a palindrome. Follow up: 思路: 题意:判断一个链表是不是回文 利用两个指 ...
- Core Animation简介
一.Core Animation简介 * Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代 ...
- java基础语法(二)--单列模式
java基础语法(二)--单列模式 /** * 功能:单列模式 * @author Administrator * */ public class SingletonTest { public sta ...