zoukankan      html  css  js  c++  java
  • HDU1177:"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<N --G, S, C denoting the number of golden medals, silver medals and copper medals respectively) and M (0<M<=N). The next N lines contain an integer P (1<=P<=8 --number of problems that have been solved by someone) and a time T(for example,"02:45:17", meaning 2 hours and 45 minutes and 17 seconds consumed according to contest rules) each. You can assume that all submit data are different.
    A test case starting with 0 0 0 0 0 terminates input and this test case should not to be processed.
     

    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.
     
    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
     
    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #define N 1000
    using namespace std;
    struct SS
    {
        int num,h,m,s;
        int no;
        int k;
    }f[N];
    int cmp(SS a,SS b)
    {
         if(a.num!=b.num)
       return a.num>b.num;
       if(a.h!=b.h)
       return a.h<b.h;
       if(a.m!=b.m)
       return a.m<b.m;
       if(a.s!=b.s)
       return a.s<b.s;
      
        //if(a.num>b.num)
        //return true;
        //if(a.h<b.h)
        //return true;
        //if(a.m<b.m)
        //return true;
        //if(a.s<b.s)
        //return true;
        //else 
        //return false;
        
    }
    int main()
    {   freopen("1.txt","r",stdin);
        int i,n,m,gold,silver,cooper,honor;
        while(cin>>n>>gold>>silver>>cooper>>m)
        {
            if(n+gold+silver+cooper+m==0)
            break;
            for(i=0;i<n;i++)
            {   
                f[i].no=i+1;
                //cin>>f[i].num>>f[i].h>>f[i].m>>f[i].s;
                scanf("%d %d:%d:%d",&f[i].num,&f[i].h,&f[i].m,&f[i].s);  
            }
            sort(f,f+n,cmp);
            for(i=0;i<n;i++)
            {
                if(gold)
                {
                    f[i].k=1;
                    gold--;
                }
                else if(silver)
                {
                    f[i].k=2;
                    silver--;
                    
                }
                else if(cooper)
                {
                    f[i].k=3;
                    cooper--;
                    
                }
                else
                {
                    f[i].k=4;
                    
                }
                
            }
            for(i=0;i<n;i++)
            {
                if(f[i].no==m)
                {
                    if(f[i].k==1)
                    cout<<"Accepted today? I've got a golden medal :)"<<endl;
                    else if(f[i].k==2)
                    cout<<"Accepted today? I've got a silver medal :)"<<endl;
                    else if(f[i].k==3)
                    cout<<"Accepted today? I've got a copper medal :)"<<endl;
                    else if(f[i].k==4)
                    cout<<"Accepted today? I've got an honor mentioned :)"<<endl;
                    break;
                }
                
            } 
        }
        
        return 0;
    }

    首先这道题他妈的题意不明白,读了半天愣是他妈看不懂m是个什么东西,后来看程序才知道。

    这道题首先进行结构体排序,排好顺序之后,从金牌往下给,金牌给完给银牌,银牌给完给铜牌,铜牌给完剩下的就是优秀奖,这个m就是说排好顺序之前的第m个人拿到的是个什么玩意儿。然后输出结果。细节是输入问题,输入时间那个地方,注意最好别用cin,容易出错,最好使用scanf。。。。。。。。排序那个地方最好使用否定排序,假如a.num!=b.num  返回a.num>b.num  if(a.h!=b.h)return a.h<b.h···················

    在一个就是跳出  输出一个语句之后是跳出状态。

    还有一个就是注意把freopen去掉。

  • 相关阅读:
    Inside The C++ Object Model
    Inside The C++ Object Model
    奇偶剪枝算法
    HDU 1088 Write a simple HTML Browser
    HDU 1084 What Is Your Grade?
    二分图的最大匹配(匈牙利算法)HDU1083
    来自codeblock 贴吧
    HDU 1075 What Are You Taking About
    HDU 1082 Matrix Chain Multiplication
    pair模板类
  • 原文地址:https://www.cnblogs.com/hezixiansheng8/p/3660753.html
Copyright © 2011-2022 走看看