比赛 I Love This Game

来源:互联网 发布:js 调用原生手机相册 编辑:程序博客网 时间:2024/05/15 09:09

Description

Do you like playing basketball ? If you are , you may know the NBA Skills Challenge . It is the content of the basketball skills . It include several parts , such as passing , shooting , and so on. After completion of the content , the player who takes the shortest time will be the winner . Now give you their names and the time of finishing the competition , your task is to give out the rank of them ; please output their name and the rank, if they have the same time , the rank of them will be the same ,but you should output their names in lexicographic order.You may assume the names of the players are unique.

Is it a very simple problem for you? Please accept it in ten minutes.
 

Input

This problem contains multiple test cases! Ease test case contain a n(1<=n<=10) shows the number of players,then n lines will be given. Each line will contain the name of player and the time(mm:ss) of their finish.The end of the input will be indicated by an integer value of zero.
 

Output

The output format is shown as sample below.
Please output the rank of all players, the output format is shown as sample below;
Output a blank line between two cases.
 

Sample Input

10Iverson 17:19Bryant 07:03Nash 09:33Wade 07:03Davies 11:13Carter 14:28Jordan 29:34James 20:48Parker 24:49Kidd 26:460
 

Sample Output

Case #1Bryant 1Wade 1Nash 3Davies 4Carter 5Iverson 6James 7Parker 8Kidd 9Jordan 10
 
字典序排序的规则,用sort排序有规则,需要注意细节:
#include <iostream>#include <algorithm>using namespace std;struct node{    string name;    int hour;    int minu;    int num;} player[10005];int cmp(node a,node b){    if(a.hour!=b.hour)        return a.hour<b.hour;    else if(a.minu!=b.minu)        return a.minu<b.minu;    else        return a.name<b.name;}int main(){    int n;    char ch;    int flag=1;    int ans=0;    while(cin>>n)    {        if(n==0)            break;        for(int i=1; i<=n; i++)        {            cin>>player[i].name>>player[i].hour>>ch>>player[i].minu;        }        if(ans)            cout<<endl;        sort(player,player+n+1,cmp);        cout<<"Case #"<<flag++<<endl;        int k=1;        player[1].num=1;        for(int i=2;i<=n;i++)        {            if(player[i].hour==player[i-1].hour&&player[i].minu==player[i-1].minu)            {                player[i].num=k;                //player[i+1].num=k;            }            else                player[i].num=k=i;        }        for(int i=1; i<=n; i++)        {            cout<<player[i].name<<" "<<player[i].num<<endl;        }        ans=1;    }    return 0;}


0 0
原创粉丝点击