HDU - 1177 Accepted Today? (Simple Sort)

Problem Description

Do you remember a sentence “Accepted today?” Yes, the sentence is mentioned frequently in lcy’s course “ACM Programming”!
The contest is still in progress this moment. How excited it is! You, smart programmer, must have AC some problems today. “Can I get copper medal, silver medal, or even golden medal?” Oh, ha-ha! You must be considering this question. And now, the last problem of this contest comes.
Give you all submitting data in the contest, and tell you the number of golden medals, silver medals and copper medals; your task is to output someone’s contest result.
Easy? Of course! I t is the reason that I designed the problem.
When you have completed this contest, please remember that sentence〃 Accepted today?〃兒

Input

Input contains multiple test cases. Each test case starts with five numbers N (4 =< N <= 130 – the total number of attendees), G, S, C (1<=G<=S<=C

Output

For each case, print a sentence in a line, and it must be one of these sentences:
Accepted today? I’ve got a golden medal :)
Accepted today? I’ve got a silver medal :)
Accepted today? I’ve got a copper medal :)
Accepted today? I’ve got an honor mentioned :)

*Note:
You will get an honor mentioned if you can’t get copper medal, silver medal or golden medal.*

Sample Input

10 1 2 3 6
2 02:45:17
2 02:49:01
2 03:17:58
2 03:21:29
4 07:55:48
3 04:25:42
3 06:57:39
2 02:05:02
2 02:16:45
2 02:41:37
0 0 0 0 0

Sample Output

Accepted today? I’ve got a silver medal :)

Problem solving ideas:

The main idea of ​​the question: a game, n people participate (the order is the number of each person), first record the total amount of each person's final answer, and the time it takes to answer the question. First of all, it is necessary to present awards to these people, with g for gold, s for silver, and c for bronze. Ask the p-th (numbered p, not rank p -- so when sorting is to record everyone's number) what award the individual should give him.

Problem solving:
The idea is very simple, that is to rank first, and then rank according to the total number of problems solved. The more problems solved, the higher the ranking;

After the sorting is completed, the number of the records between them can be added to know the rank of the p-th person, and thus it can be determined what prize he is.

Code:

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

typedef struct{
    int id;             //原始编号
    int num;
    int h;
    int m;
    int s;
    int level;        //获奖等级 , 0 -->golden , 1 --> sliver , 2 --> copper , 3 --> honer
}Attendee;

bool method(Attendee a , Attendee b){
    if(a.num != b.num){
        return a.num > b.num;
    }else if(a.h != b.h){
        return a.h < b.h;
    }else if(a.m != b.m){
        return a.m < b.m;
    }else if(a.s != b.s){
        return a.s < b.s;
    }
}

string str[4] = {"Accepted today? I've got a golden medal :)" , "Accepted today? I've got a silver medal :)" ,
 "Accepted today? I've got a copper medal :)" , "Accepted today? I've got an honor mentioned :)"};

Attendee att[140];

int main(){
    //freopen("D://testData//1177.txt" , "r" , stdin);
    int n , gol , sli , cop , p , flag = 0;
    int i;
    while(scanf("%d %d %d %d %d",&n , &gol , &sli , &cop , &p) != EOF){
        if(n == 0 && gol == 0 && sli == 0 && cop == 0 && p == 0)
            break;

        flag = 0;

        for(i = 0 ; i < n ; i ++ ){
            scanf("%d %d:%d:%d",&att[i].num , &att[i].h , &att[i].m , &att[i].s);
            att[i].id = i;
            att[i].level = -1;
        }

        sort(att , att + n , method);

        for(i = 0 ; i < gol + sli + cop ; i ++){    //不在前(gol + sli + cop)名,那就是honer 奖。
            if(i < gol){
                att[i].level = 0;
            }else if(i < gol + sli){
                att[i].level = 1;
            }else{
                att[i].level = 2;
            }

            if(att[i].id + 1 == p){
                cout<<str[att[i].level]<<endl;
                flag = 1;
                break;
            }
        }

        if(flag == 0)
            cout<<str[3]<<endl;
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325807354&siteId=291194637