Daily Programming – Issue 287: C Language Competition

1059 C Language Competition

If you have any questions, comments, or suggestions regarding Daily Programming, please leave a message on our public account or directly contact QQ474356284 (note Daily Programming).

The C Language Competition is a fun contest hosted by the School of Computer Science at Zhejiang University. Since the purpose of the competition is for fun, the award rules are quite amusing:

  • 0. The champion will win a “Mystery Award” (such as a very large collection of student research papers…).

  • 1. Students ranked at prime numbers will win the best prize – a Minion toy!

  • 2. Others will receive chocolate.

Given the final rankings of the competition and a series of participant IDs, you need to provide the prizes that these participants should receive.

Input Format:

The first line of input gives a positive integer N (104), which is the number of participants. The next N lines give the final rankings, with each line providing a participant’s ID (composed of 4 digits) in ranking order. Following this, a positive integer K is given along with K IDs to query.

Output Format:

For each queried ID, output <span>ID: Prize</span>, where the prize can either be <span>Mystery Award</span> (神秘大奖), <span>Minion</span> (小黄人), or <span>Chocolate</span> (巧克力). If the queried ID is not in the rankings, print <span>Are you kidding?</span> (耍我呢?). If the ID has already been checked (i.e., the prize has already been claimed), print <span>ID: Checked</span> (不能多吃多占).

Input Sample:

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

Output Sample:

8888: Minion
0001: Chocolate
1111: Mystery Award
2222: Are you kidding?
8888: Checked
2222: Are you kidding?

Daily Programming - Issue 287: C Language Competition

Code Implementation:

#include <iostream>
#include <cmath>
#include <set>
using namespace std;
//灰灰考研@一航代码
int ran[10000];
bool isprime( int a )
{
    if ( a <= 1 )
        return(false);
    int Sqrt = sqrt( (double) a );
    for ( int i = 2; i <= Sqrt; i++ )
    {
        if ( a % i == 0 )
            return(false);
    }
    return(true);
}


int main()
{
    int n, k;
    scanf( "%d", &n );
    for ( int i = 0; i < n; i++ )
    {
        int id;
        scanf( "%d", &id );
        ran[id] = i + 1;
    }
    scanf( "%d", &k );
    set<int> ss;
    for ( int i = 0; i < k; i++ )
    {
        int id;
        scanf( "%d", &id );
        printf( "%04d: ", id );
        if ( ran[id] == 0 )
        {
            printf( "Are you kidding?\n" );
            continue;
        }
        if ( ss.find( id ) == ss.end() )
        {
            ss.insert( id );
        } else {
            printf( "Checked\n" );
            continue;
        }
        if ( ran[id] == 1 )
        {
            printf( "Mystery Award\n" );
        }else if ( isprime( ran[id] ) )
        {
            printf( "Minion\n" );
        }else {
            printf( "Chocolate\n" );
        }
    }
    return(0);
}</int></set></cmath></iostream>

Tomorrow’s Preview: Eddington Number

British astronomer Eddington loved cycling. It is said that to show off his cycling skills, he defined an “Eddington number” E, which satisfies that there are E days of cycling more than E miles, the maximum integer E. It is said that Eddington himself had an E equal to 87.

Now given a person’s N days of cycling distances, please calculate the corresponding Eddington number E (N).

Input Format:

The first line of input gives a positive integer N (105), which is the number of consecutive cycling days; the second line gives N non-negative integers representing the cycling distance for each day.

Output Format:

Output the Eddington number for N days in one line.

Input Sample:

10
6 7 6 9 3 10 8 2 7 8

Output Sample:

6

Daily Programming - Issue 287: C Language Competition

Daily Programming - Issue 287: C Language Competition

Leave a Comment