PAT B -1059 C language competition (20 points)

Click on the link full solution summary PAT B -AC

Topic:
C language contest is hosted by Zhejiang University School of Computer joy of a contest. Since the subject is race for fun, award rules will develop very funny:

  • 0, the winner will win a "mystery prize" (such as a very huge student research papers ......).
  • 1 ranking for the prime number of students will win the best prizes - small yellow man doll!
  • 2, others will get chocolate.

Given the game's final ranking and a series of entrants ID, you have to give these contestants should get the prize.

Input format:
input of the first row is given a positive integer N (≦ 10 . 4 ), a number of participants. Then given final rankings N rows, each row gives an entrant ID (4 digits) ranking order. Next is given a positive integer K and the K ID to be queried.

Output formats:
output ID in a row for each ID to be queried: prizes, or prizes which are Mystery Award (mystery prize), or the Minion (small yellow people), or Chocolate (chocolate). If the ID check is simply not ranked in print Are you kidding? (I'm playing it?). If the ID has been checked up (ie prizes already received over), print ID: Checked (can not eat too much of).

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?

My code:

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件

int Is_sushu(int a)
{
    if(a==2||a==3) return 1;
    for(int i=2;i<=sqrt(a);i++)
    {
        if(a%i == 0) return 0;
        if(i == int(sqrt(a)))return 1;
    }
}

int main()
{
    int N;
    cin>>N;
    int Ranking[10010]={0};
    int first=10000;
    for(int i=0;i<N;i++)
    {
        int t;
        cin>>t;
        Ranking[t]=i+1;
    }

    int M;
    cin>>M;
    for(int i=0;i<M;i++)
    {
        int t;
        cin>>t;
        if(Ranking[t]==0)printf("%04d: Are you kidding?\n",t);
        else if(Ranking[t]==10010)printf("%04d: Checked\n",t);
        else if(Ranking[t]==1)printf("%04d: Mystery Award\n",t);
        else if(Is_sushu(Ranking[t]))printf("%04d: Minion\n",t);
        else printf("%04d: Chocolate\n",t);

        if(Ranking[t])Ranking[t]=10010;
    }

    return 0;
}

Published 82 original articles · won praise 1 · views 1676

Guess you like

Origin blog.csdn.net/qq_34451909/article/details/104868881