I Love This Game
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5254 Accepted Submission(s): 1817
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.
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.
Please output the rank of all players, the output format is shown as sample below;
Output a blank line between two cases.
Sample Input
10 Iverson 17:19 Bryant 07:03 Nash 09:33 Wade 07:03 Davies 11:13 Carter 14:28 Jordan 29:34 James 20:48 Parker 24:49 Kidd 26:46 0
Sample Output
Case #1 Bryant 1 Wade 1 Nash 3 Davies 4 Carter 5 Iverson 6 James 7 Parker 8 Kidd 9 Jordan 10
当有三个以上的第一名时,下面的代码只能使前两个为第一名,自己改了一下让程序变为有几个第一名就输出几个第一名,但是提交杭电结果为WA,不知道为什么会这样,可能是我没完全理解题意吧。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct sa
{
char name[20];
int hour,minute,rank;
}p[100],pp[100];
int cmp(sa a,sa b)
{
if(a.hour==b.hour)
{
if(a.minute==b.minute)return (strcmp(a.name,b.name)<0);
return a.minute<b.minute;
}
return a.hour<b.hour;
}
int main()
{
int n,cas=1;
while(scanf("%d",&n),n)
{
for(int i=0;i<n;i++)
{
scanf("%s %d:%d",&p[i].name,&p[i].hour,&p[i].minute);
}
sort(p,p+n,cmp);
if(cas!=1)printf("\n");
printf("Case #%d\n",cas++);
pp[0]=p[0];
pp[0].rank=1;
int k=0,r=1;
printf("%s %d\n",p[0].name,r);
for(int i=1;i<n;i++)
{
int flag=0;
if(p[i].hour!=pp[k].hour||p[i].minute!=pp[k].minute)
{
r=r+1;
flag=1;
}
printf("%s %d\n",p[i].name,r);
if(flag==0)
{
r=r+1;
}
pp[++k]=p[i];
}
}
return 0;
}