# I Love This Game HDU – 2115

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.
InputThis 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.
OutputThe 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

10
Iverson 17:19
Bryant 07:03
Nash 09:33
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



#include<stdio.h>
#include<stdlib.h>
struct player{
char name[30];
int m;
int s;
int alls;//将分钟数都化成秒数
int g;//等级
};
void change(struct player *p,int n){
for(int i = 0; i<n; i++){
p[i].alls = p[i].m*60+p[i].s;
}
}//计算总秒数
void sort(struct player *p,int n){
struct player temp;
int cnt=1;
for(int i=0; i<n; i++){
for(int j=0; j<n-i-1; j++){
if( p[j+1].alls < p[j].alls){
temp = p[j+1];
p[j+1] = p[j];
p[j] = temp;
}
}
}//排序
for(int i=0; i<n; i++){
if(p[i].alls==p[i+1].alls){
p[i+1].g= cnt;
p[i].g = cnt;
i++;
cnt++;//会到里面是因为有一样的，所以cnt要加2，里面加1外面加1就可以了
}
else{
p[i].g=cnt;

}
cnt++;
}//给排名
}

int main(){
int n;
int j=1;
while(scanf("%d",&n)&&n){
struct player *p=(struct player*)malloc(n*sizeof(struct player));
for(int i=0; i<n; i++){
scanf("%s%d:%d",p[i].name,&p[i].m,&p[i].s);
}
change(p,n);
sort(p,n);

if(j==1){
printf("Case #%d\n",j);
}
else{
printf("\nCase #%d\n",j);
}//注意看换行符的输出位置
for(int i=0; i<n; i++){
printf("%s %d\n",p[i].name,p[i].g);
}
j++;
//	printf("\n");
}

return 0;
} 

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客