C語言競賽是浙江大學計算機學院主持的一個歡樂的競賽。既然競賽主旨是爲了好玩,頒獎規則也就制定得很滑稽:
0. 冠軍將贏得一份“神祕大獎”(比如很巨大的一本學生研究論文集……)。
1. 排名爲素數的學生將贏得最好的獎品 —— 小黃人玩偶!
2. 其他人將得到巧克力。
給定比賽的最終排名以及一系列參賽者的ID,你要給出這些參賽者應該獲得的獎品。
輸入格式:
輸入第一行給出一個正整數N(<=10000),是參賽者人數。隨後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 <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
bool prime(int x);
struct attender
{
int rank;
int num;
bool flag;
};
int main()
{
int i,n;
attender arr[10005];
cin>>n;
for(i=0;i<n;i++)
{
arr[i].rank = i+1;
cin>>arr[i].num;
arr[i].flag = false;
}
int temp,m;
bool f;
cin>>m;
while(m--)
{
cin>>temp;
f = false;
for(i=0;i<n;i++)
{
if(arr[i].num == temp)
{
f = true;
cout<<setw(4)<<setfill('0')<<arr[i].num<<": ";
if(arr[i].flag == false)
{
arr[i].flag = true;
if(arr[i].rank == 1)
cout<<"Mystery Award"<<endl;
else if(prime(arr[i].rank) == true)
cout<<"Minion"<<endl;
else
cout<<"Chocolate"<<endl;
}
else
cout<<"Checked"<<endl;
break;
}
}
if(f == false)
cout<<temp<<": Are you kidding?"<<endl;
}
return 0;
}
bool prime(int x)
{
int i;
if(x <= 1)
return false;
if(x == 2)
return true;
else
{
for(i=2;i<=sqrt((double)x)+1;i++)
{
if(x%i == 0)
return false;
}
return true;
}
}