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. XML 是一种元语言, 可以用它来描述其他语言。

    A.正确 B.错误 解答:B XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard Generalized Markup L ...

  2. 曲线学习PyQt5方案一

    PyQt5官方网站没直接给出API,这个很操蛋啊. PtQt4官方网站有完整的API,C++版本的Qt5也能找到完整的API资料.由于Qt5的C++和Python3的类和函数实现应该是一致的,所以可以 ...

  3. requirejs源码分析,使用注意要点

    本文将深度剖析require.js代码,为了是大家更高效.正确的去使用它,本文不会介绍require的基本使用! 概要 先来一个流程图来概要一下大概流程 在require中,根据AMD(Asynchr ...

  4. 怎样使用DWZ?

    首先说明,这篇文章不是解说DWZ内部实现原理的,也不打算分析它的源代码,这里仅仅是演示一下,怎样将DWZ框架整合到项目中去. 刚刚过去的项目中,前台UI使用的是DWZ.因为之前项目的开发环境都已经搭建 ...

  5. 自动化测试环境准备robotframework

    (一)针对python2.7版本的自动化环境准备: python 下载地址: https://www.python.org/downloads/ 这里选择Python2.7系列的,后面涉及到wxPyt ...

  6. delay()延迟

    jquery的delay()方法: delay() 方法对队列中的下一项的执行设置延迟. 封装方法: $.fn.fadeInWithDelay = function(){ var delay = 0; ...

  7. 06.Curator Barrier

        分布式Barrier是这样一个类: 它会阻塞所有节点上的等待进程,知道某一个被满足, 然后所有的节点继续进行.     比如赛马比赛中, 等赛马陆续来到起跑线前. 一声令下,所有的赛马都飞奔而 ...

  8. node npm

    node.js -npm 查看npm版本号$ npm -v 全局安装npm$ npm install npm -g 安装模块$ npm install <module name> --本地 ...

  9. 如何使用java指令执行含package的class文件

    代码文件存放在E:/Temp/JAVA_TEMP/tmp文件夹,代码如下: package tmp; public class Temp { public static void main(Strin ...

  10. python学习笔记(四)— 函数

    一.函数是什么? 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的,编程中的函数在英文中也有很多不同的叫法.在BASIC中叫做subroutine(子过程或子程序),在Pasc ...