HDU——1177 Accepted Today?(简单排序)

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 :)

解题思路:

题目大意:一场比赛,n个人参加(顺序即每个人的编号),先记录了每个人最后的答题总量,以及答题所用时间。先需要对这些人进行颁奖,金奖g个,银奖s个,铜奖c个。问第p(编号为p , 不是排名为p —-因此在进行排序是要记录一下每个人的编号)个人应该颁给他什么奖。

解题:
思路很简单,就是先排个名,按解题总数排,解题数越多,则排名越高;若解题数相同,则比较时间,用时少者胜。

排完序后,再加上之间记录的编号便能够知道第p个人的排名 , 由此就可以确定他是什么奖了。

代码:

#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;
}

猜你喜欢

转载自blog.csdn.net/sinat_38052999/article/details/80144929