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 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 (≤104), 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 [简单]的更多相关文章
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- 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与 ...
- PAT 1102 Invert a Binary Tree[比较简单]
1102 Invert a Binary Tree(25 分) The following is from Max Howell @twitter: Google: 90% of our engine ...
随机推荐
- 原生js怎么删除一个 div
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 使用GitHub建立个人网站
使用GitHub建立个人网站 1 Git简介 2 为什么使用Github Pages 3 创建Github Pages 3.1 安装git工具. 3.2 两种pages模式 3.3 创建步骤 3.4 ...
- MyBatis常用对象SqlSessionFactory和SqlSession介绍和运用
学习框架一个比较好的路径阅读源码.本文介绍的SqlSessionFactory和SqlSession.可以通过了解SqlSessionFactory接口和SqlSession接口以及两个的实现类入手, ...
- 在Swing的组件中,基本上都是在AWT组件的名称前面加“J”
在Swing的组件中,基本上都是在AWT组件的名称前面加“J”. 一般情况下,除了Choise等组件: import javax.swing.*;好要加上:import java.awt.*以及imp ...
- 5.3 SpEL语法
SqEL是一个可以独立于spring的表达式语言,即它可以用在XML中对语法进行简化 5.3 SpEL语法5.3.1 基本表达式一.字面量表达式: SpEL支持的字面量包括:字符串.数字类型(int. ...
- db2 导入cvs
1) 打开DB2 命令行 2) 如果是第一次连接到远程的DB2 数据库:如果不是,请直接跳转到3) 在DB2 命令行窗口执行: catalog tcpip node DB21 ...
- ACM计算几何模板——圆和球
#include <iostream> #include <cmath> using namespace std; #define eps 1e-10 /********** ...
- C++ STL迭代器与索引相互转换
0 前言 C++ STL提供了vector.list等模板容器,极大地方便了编程使用. “遍历”是对容器使用的最常用的操作. 使用迭代器来遍历是最好最高效的遍历方法. 当然,对于有些容器的遍历除了使用 ...
- hdu 4715(打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4715 思路:先打个素数表,然后判断一下就可以了. #include<iostream> # ...
- 理解javascript函数调用和“this”
http://blog.csdn.net/littlechang/article/details/8180550