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. 【转】【iOS测试系列】常用测试小插件的使用

    背景介绍 由于iOS系统的限制,在非越狱的自动化测试中无法实现一些常用的功能,比如不同应用之间来回切换.模拟全局的点击事件等等.但是在越狱的环境下,这些限制就不存在了,我们可以利用各种小插件来实现我们 ...

  2. [android] AndroidManifest.xml - 【 manifest -> permission】

    在  API Level 1 时被引入 语法: <permission android:description="string resource" android:icon= ...

  3. C++ 类的构造函数使用规则

    //类的构造函数使用规则 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class Poi ...

  4. MathType二次偏导怎么表示

    求导以及求偏导运算在数学中是很重要的一个部分,尤其是在高等数学中,基本都由函数的导数与偏导组成,很多公式定理也是关于这方面的,如果少了这一部分,数学将会黯然失色.因此在文档中涉及到这些内容时,必然会少 ...

  5. 使用 Estimator 构建卷积神经网络

    来源于:https://tensorflow.google.cn/tutorials/estimators/cnn 强烈建议前往学习 tf.layers 模块提供一个可用于轻松构建神经网络的高级 AP ...

  6. THINKPHP5获取设置缓存的例子

    在THINKPHP5中 缓存的配置放在了config.php文件中 代码如下 如何设置缓存? 可以使用静态方法 Cache::set('key',$value,3600);//存储缓存 Cache:: ...

  7. 指针与C++基本原理

    面向对象编程与传统的过程性编程的区别在于,OOP强调的是在运行阶段(而不是编译阶段)进行决策.运行阶段指的是程序正在运行时,编译阶段指的是编译器将程序组合起来时.运行阶段决策就好比度假时,选择参观那些 ...

  8. 【BZOJ3809/3236】Gty的二逼妹子序列 [Ahoi2013]作业 莫队算法+分块

    [BZOJ3809]Gty的二逼妹子序列 Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b ...

  9. java web页面跳转 总结

    Servlet中forward和redirect的区别 forward方式:request.getRequestDispatcher("/somePage.jsp").forwar ...

  10. nginx提高加载静态文件速度

    1.本来对于静态网页,我们不需要放在应用容器中,原因一时由于应用服务器是用来解析动态网页的,针对静态网页本来就性能不高,而且还会占用应用容器的资源,所以我们专门使用nginx用来解析静态网页.     ...