当前位置:网站首页>PAT B1059

PAT B1059

2022-06-25 19:57:00 Madness makes freedom

1059 C Language contest (20 branch )

C The language contest is a happy contest hosted by the school of computer science of Zhejiang University . Since the theme of the competition is for fun , The award rules are funny :

  • 0、 The champion will win a “ Mystery Award ”( For example, a huge collection of student research papers ……).
  • 1、 Students who rank prime will win the best prize —— Little yellow doll !
  • 2、 Others will get chocolate .

The final ranking of a given competition and the ranking of a series of contestants ID, You have to give the prizes that these contestants deserve .

Input format :

The first line of input gives a positive integer N(≤104), Is the number of contestants . And then N Row gives the final ranking , Each line gives a contestant's name in order of ranking ID(4 Digit composition ). Next, we give a positive integer K as well as K You need to query ID.

Output format :

For each query ID, Output in one line ID: Prize , One of the prizes or Mystery Award( Mystery Award )、 Or is it Minion( Minions )、 Or is it Chocolate( chocolate ). If the investigation ID It's not in the ranking at all , Print Are you kidding?( You're kidding me ?). If it's time to ID Already checked ( That is, the prize has been received ), Print ID: Checked( Don't eat too much ).

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?

Put the contestant's ID Treat as a subscript !!!!

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool isPrimer(int n);

int main()
{
    int n,a[10000]={0},id;
    cin >> n;
    for(int i=1;i<=n;++i)
    {
        cin >> id;
        a[id]=i;
    }
    int k;
    cin >> k;
    int hashtable[10000]={0};
    for(int i=1;i<=k;++i)
    {
        cin >> id;
        if(a[id]==0)
            printf("%04d: Are you kidding?\n",id);
        else if(a[id]==1)
        {
            if(hashtable[id]==0)
            {
                printf("%04d: Mystery Award\n",id);
                hashtable[id]=1;
            }
            else
                printf("%04d: Checked\n",id);
        }
        else if(isPrimer(a[id]))
        {
            if(hashtable[id]==0)
            {
                printf("%04d: Minion\n",id);
                hashtable[id]=1;
            }
            else
                printf("%04d: Checked\n",id);
        }
        else
        {
            if(hashtable[id]==0)
            {
                printf("%04d: Chocolate\n",id);
                hashtable[id]=1;
            }
            else
                printf("%04d: Checked\n",id);
        }
    }

    return 0;
}

bool isPrimer(int n)
{
    int sqr=sqrt(n*1.0);
    for(int i=2;i<=sqr;++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

原网站

版权声明
本文为[Madness makes freedom]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190512259940.html