当前位置: 代码迷 >> 综合 >> PTA C语言竞赛 (20分)
  详细解决方案

PTA C语言竞赛 (20分)

热度:78   发布时间:2024-03-07 13:49:46.0

“人其实就这一辈子,我想要的生活不是安逸的,虽然很累,但我想要辉煌的人生,所以也一直在为此努力、不松懈。我所理解的辉煌人生,不是挣了多少钱、做了多伟大的事,而是将人生过得有意义,不碌碌无为。哪怕前进得很慢,但是每分每秒都在往前走,去追求梦想。”                                                                                                                               ----喻言

C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛。既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽:

  • 0、冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……)。
  • 1、排名为素数的学生将赢得最好的奖品 —— 小黄人玩偶!
  • 2、其他人将得到巧克力。

给定比赛的最终排名以及一系列参赛者的 ID,你要给出这些参赛者应该获得的奖品。

输入格式:

输入第一行给出一个正整数 N(≤10?4??),是参赛者人数。随后 N 行给出最终排名,每行按排名顺序给出一位参赛者的 ID(4 位数字组成)。接下来给出一个正整数 K 以及 K 个需要查询的 ID。

输出格式:

对每个要查询的 ID,在一行中输出 ID: 奖品,其中奖品或者是 Mystery Award(神秘大奖)、或者是 Minion(小黄人)、或者是 Chocolate(巧克力)。如果所查 ID 根本不在排名里,打印 Are you kidding?(耍我呢?)。如果该 ID 已经查过了(即奖品已经领过了),打印 ID: Checked(不能多吃多占)。

输入样例:

6
1111
6666
8888
1234
5555
0001
6
8888
0001
1111
2222
8888
2222

输出样例:

8888: Minion
0001: Chocolate
1111: Mystery Award
2222: Are you kidding?
8888: Checked
2222: Are you kidding?
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include <numeric>
#include<unordered_set>
#include <climits>//INT_100010n
//#include<bits/stdc++.h>
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define INF 0x7fffffff;
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
#define LL unsigned int
#define mod 1000000007
//#define wc 1e-8
typedef long long ll;
using namespace std;
int a[10010],s[10010];
bool pd(int x)
{if(x==2||x==3)return true;else{for(int i=2; i*i<=x; ++i)if(x%i==0)return false;return true;}
}int main()
{int n;cin>>n;for(int i=1; i<n+1; ++i){scanf("%d",&s[i]);a[i]=1;}int m,ss,i=1;cin>>m;for(int j=0; j<m; ++j){scanf("%d",&ss);i=1;for(; i<n+1; ++i)if(ss==s[i])break;if(i==n+1)printf("%04d: Are you kidding?\n",ss);else if(a[i]==0)printf("%04d: Checked\n",ss);else{a[i]=0;if(i==1)printf("%04d: Mystery Award\n",ss);else{bool fg=pd(i);if(fg)printf("%04d: Minion\n",ss);elseprintf("%04d: Chocolate\n",ss);}}}return 0;
}

 

  相关解决方案