hdu-2115(结构体,sort) I Love This Game

来源:互联网 发布:ubuntu mentohust下载 编辑:程序博客网 时间:2024/05/17 12:48

I Love This Game

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6387    Accepted Submission(s): 2187


Problem 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
 
# include<stdio.h># include<string.h># include<algorithm>using namespace std;struct bb{char a[15];char b[15];}c[10];int cmp1(bb x,bb y){return strcmp(x.b,y.b)<0;}int cmp2(bb x,bb y){if(strcmp(x.b,y.b)==0) return strcmp(x.a,y.a)<0;else return strcmp(x.b,y.b)<0;}int main(){  int m,k=0;  int q=1;  while(scanf("%d",&m)&&m)   {    if(q>1)    printf("\n");//大坑 栽在格式上已经数不清了。。。    int i,t;    for(i=0;i<m;i++)     scanf("%s %s",c[i].a ,c[i].b);    int *z=(int*)malloc(sizeof(int)*m);    memset(z,0,sizeof(z));    sort(c,c+m,cmp1);    sort(c,c+m,cmp2);    k++;    printf("Case #%d\n",k);     for(i=0,t=1;i<m;i++)       {z[i]=t;      if(strcmp(c[i].b ,c[i+1].b )!=0)t=i+2;      }    for(i=0;i<m;i++)     printf("%s %d\n",c[i].a,z[i]);     q++;   }}
水题,格式略坑

0 0
原创粉丝点击