PAT_A 1116. Come on! Let's C (20)

2023-11-05 01:38
文章标签 20 pat let 1116 come

本文主要是介绍PAT_A 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 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:

  1. The Champion will receive a “Mystery Award” (such as a BIG collection of students’ research papers…).
  2. Those who ranked as a prime number will receive the best award – the Minions (小黄人)!
  3. 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?

  • 分析
    待续
  • code
#include<iostream>
#include<queue>
#include<map>
#include<exception>
#include<iomanip>
using namespace std;/**采用map的方式更为合理,键为字符串,值为排序*考察排序*还得判断素数* */
bool isPrime(int n)
{if(n<2)return false;for(int i=2;i<n;i++){if(!(double(n)/(double)i-n/i))return false;}return true;
}
int main()
{int m=0;int n=0;int tmp=0;map<int,int> rank;cin>>m;queue<int> que;for(int i=1;i<=m;i++){int tmp;cin>>tmp;rank[tmp]=i;}cin>>n;int max=10000;int max2=0;for(int i=0;i<n;i++){cin>>tmp;que.push(tmp);int tmp2=0;try{tmp2=rank.at(tmp);if(max>tmp2){max=tmp2;max2=tmp;}}catch(exception&e){continue;}}for(int i=0;i<n;i++){int tmp=que.front();que.pop();cout.fill('0');cout<<setw(4)<<tmp<<": ";cout.fill(' ');try{int tmp2=rank.at(tmp);if(tmp2==-3){cout<<"Checked"<<endl;continue;}else if(isPrime(tmp2)==true){cout<<"Minion"<<endl;rank[tmp]=-3;continue;}else if(tmp2==max){cout<<"Mystery Award"<<endl;rank[tmp]=-3;continue;}else {cout<<"Chocolate"<<endl;rank[tmp]=-3;continue;}}catch(exception&e){cout<<"Are you kidding?"<<endl;}}return 0;
}

这篇关于PAT_A 1116. Come on! Let's C (20)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/346528

相关文章

20.Spring5注解介绍

1.配置组件 Configure Components 注解名称说明@Configuration把一个类作为一个loC容 器 ,它的某个方法头上如果注册7@Bean , 就会作为这个Spring容器中的Bean@ComponentScan在配置类上添加@ComponentScan注解。该注解默认会扫描该类所在的包下所有的配置类,相当于之前的 <context:component-scan>@Sc

PAT-1039 到底买不买(20)(字符串的使用)

题目描述 小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如,YrR8RrY是小红想做的珠串;那么ppRYYGrrYBR2258可以

PAT-1028

题目描述 某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的老人,而今天是2014年9月6日,所以超过200岁的生日和未出生的生日都是不合理的,应该被过滤掉。 输入描述: 输入在第一行给出正整数N,取值在(0, 105];随后N行,每行给出1个人的姓名(由不超过5个

HTML(20)——定位

定位 作用:灵活的改变盒子在网页中的位置 实现: 定位模式:position边偏移:设置盒子的位置 leftrighttopbottom 相对定位 position:relative 改变位置的参照物是自己原来的位置,并且不脱标占位,标签显示模式特点不变 绝对定位 position:absolute 使用场景:子级绝对定位,父级相对定位  脱标不占位参照物:先找最近的已经

C++20中的Feature Test Mocros

C++20定义了一组预处理器宏,用于测试各种语言和库的feature。       Feature Test Mocros(特性测试宏)是C++20中引入的一种强大机制,用于应对兼容性问题。Feature Test Mocros作为预处理器指令(preprocessor directives)出现,它使你能够在编译过程中仔细检查特定语言或库功能(particular language

2025秋招NLP算法面试真题(二)-史上最全Transformer面试题:灵魂20问帮你彻底搞定Transformer

简单介绍 之前的20个问题的文章在这里: https://zhuanlan.zhihu.com/p/148656446 其实这20个问题不是让大家背答案,而是为了帮助大家梳理 transformer的相关知识点,所以你注意看会发现我的问题也是有某种顺序的。 本文涉及到的代码可以在这里找到: https://github.com/DA-southampton/NLP_ability 问题

使用Let‘s Encrypt 申请通配符证书

为什么不使用阿里云/腾讯云等公有云厂商提供的免费证书? 上篇介绍了从阿里云上面申请免费证书,有效期一年 为网站配置https证书 公有云提供的证书不支持通配符,只支持某个确定的解析。 不管是二级域名还是三级域名,只要是具体的确定的地址,都可以使用。 对于某个域名,如果DNS解析很少,如只有mail.abc.com,www.abc.com,blog.abc.com, 用公有云需要分别为

【LocalAI】(13):LocalAI最新版本支持Stable diffusion 3,20亿参数图像更加细腻了,可以继续研究下

最新版本v2.17.1 https://github.com/mudler/LocalAI/releases Stable diffusion 3 You can use Stable diffusion 3 by installing the model in the gallery (stable-diffusion-3-medium) or by placing this YAML fi

每日文献:2018-02-20

自然选择的分子印迹(精读第一天) 由于最近不知不觉开始涉及群体遗传学,所以准备精读(其实就是原文翻译)一篇review尽力去了解这个我陌生的领域。文章原标题为Molecular Signatures of Natural Selection, 作者Rasmus Nielsen。 简介 群体遗传学数十年来一直被一个问题所困扰,那就是如果在观察物种中存在一个遗传变异,那么应该如何定量得描述

每日一题——Python代码实现PAT乙级1048 数字加密(举一反三+思想解读+逐步优化)五千字好文

一个认为一切根源都是“自己不够强”的INTJ 个人主页:用哲学编程-CSDN博客专栏:每日一题——举一反三Python编程学习Python内置函数 Python-3.12.0文档解读 目录 初次尝试  再次尝试 代码点评 代码结构 时间复杂度 空间复杂度 优化建议 我要更强 优化建议 完整代码及注释 时间复杂度和空间复杂度分析 进一步优化 哲学和编程思想 模块化