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 (≤10​4​​), 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?

题目大意:给出n个排名的id,序号代表排名,如果是第一名输出Mystery Award,素数名输出Minion,其他人输出Chocolate,重复查询提示。

水水的AC:

#include <iostream>
#include <algorithm>
#include<cstdio>
#include <map>
#include<cmath>
using namespace std; map<int,string> award;
map<int,int> query;
bool prime(int a){
int q=sqrt(a);
for(int i=;i<=q;i++){
if(a%i==){
return false;
}
}
return true;
}
int main()
{
int n,no;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&no);
if(i==){
award[no]="Mystery Award";
}else{
if(prime(i+)){
award[no]="Minion";
}else{
award[no]="Chocolate";
}
}
}
int m;
scanf("%d",&m);
for(int i=;i<m;i++){
scanf("%d",&no);
if(award.count(no)==){
printf("%04d: Are you kidding?\n",no);
}else {
if(query.count(no)==){
printf("%04d: Checked\n",no);
}else{//使用printf怎么输出String啊啊?好像没办法。。。
printf("%04d: ",no);
cout<<award[no]<<"\n";
query[no]=;
}
}
}
return ;
}

//有一个槽点,就是在写最后出现了个问题,代码中有注释,所以就混合使用printf和cout输出了,罪过。

1.查了一下发现是需要将其转换成char*类型,直接使用:

printf("%04d: %s\n",no,award[no].c_str());

即可!c_str()就是将string转换为char*的函数!!!

PAT 1116 Come on! Let's C [简单]的更多相关文章

  1. PAT 1002. A+B for Polynomials (25) 简单模拟

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  2. PAT 1116 Come on! Let's C

    1116 Come on! Let's C (20 分)   "Let's C" is a popular and fun programming contest hosted b ...

  3. PAT Sign In and Sign Out[非常简单]

    1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...

  4. PAT 1069 The Black Hole of Numbers[简单]

    1069 The Black Hole of Numbers(20 分) For any 4-digit integer except the ones with all the digits bei ...

  5. pat 1116 Come on! Let's C(20 分)

    1116 Come on! Let's C(20 分) "Let's C" is a popular and fun programming contest hosted by t ...

  6. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  7. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  8. PAT 数列求和-加强版   (20分)(简单模拟)

    给定某数字A(1≤A≤9)以及非负整数N(0≤N≤100000),求数列之和S=A+AA+AAA+⋯+AA⋯A(N个A).例如A=1, N=3时,S=1+11+111=123 输入格式: 输入数字A与 ...

  9. PAT 1102 Invert a Binary Tree[比较简单]

    1102 Invert a Binary Tree(25 分) The following is from Max Howell @twitter: Google: 90% of our engine ...

随机推荐

  1. js学习笔记25----Event对象

    Event : 事件对象,当一个事件发生的时候,和当前这个对象发生的这个事件有关的一些详细的信息都会被临时保存到一个指定的地方-event 对象,供我们在需要时调用. 事件对象必须在一个事件调用的函数 ...

  2. 关于Nvelocity的主要语法和一些代码示例

    context.Response.ContentType = "text/html"; VelocityEngine vltEngine = new VelocityEngine( ...

  3. Xcode升级后插件失败解决方法

    大家都知道每次升级Xcode 然后插件都不能用了,最根本的原因是每一个插件都有个Info.plist文件,这个文件里有个key-DVTPlugInCompatibilityUUIDs记录了能够使用该插 ...

  4. COCOS2D-X多层单点触摸分发处理方案?

    如今的问题是点击button的时候,会触发底层的触摸事件,怎么不触发底层的触摸事件啊?  

  5. 【转】Native Thread for Win32 A- Create Thread(通俗易懂,非常好)

    http://www.bogotobogo.com/cplusplus/multithreading_win32A.php Microsoft Windows operating system's s ...

  6. galera安装之编译安装xtrabackup 2.2.11

    ----1.编译安装percona-xtrabackup yum -y install cmake gcc gcc-c++ libaio libaio-devel automake autoconf ...

  7. HDU4081 Qin Shi Huang&#39;s National Road System【prim最小生成树+枚举】

    先求出最小生成树,然后枚举树上的边,对于每条边"分别"找出这条割边形成的两个块中点权最大的两个 1.因为结果是A/B.A的变化会引起B的变化,两个制约.无法直接贪心出最大的A/B. ...

  8. 通过Servlet获取初始化参数

    获取初始化参数在web.xml中配置Servlet时,可以配置一些初始化参数.而在Servlet中可以通过ServletConfig接口提供的方法来获取这些参数.(其实还可以通过ServletCont ...

  9. Android 切换主题 (二)

    Android 切换主题 (二) 背景 我原来写过一篇文章关于 android 切换主题的文章 -- Android 切换主题以及换肤的实现 , 里面介绍了如何使用 setTheme() 来切换主题, ...

  10. java方法的理解、调用栈与异常处理

    一.流程分支 If/else :基于boolean值的双分支 Switch:基于数字(整数.char.byte.枚举).字符串 类型的多分支 Int month =5; Switch 二.方法meth ...