hdu-2115

来源:互联网 发布:干洗好的软件 编辑:程序博客网 时间:2024/05/22 06:05

I Love This Game

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


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 node{
char name[100];
int m;
int s;
int time;
int num;
}d[11];
int cmp(node x,node y){
return (x.time==y.time? strcmp(x.name,y.name)>1:x.time<y.time);
}
int main()
{
  int n,i,k=1;
  while(~scanf("%d",&n),n!=0){
  for(i=0;i<n;i++){
  scanf("%s%d:%d",d[i].name,&d[i].m,&d[i].s);
  d[i].time=d[i].m*60+d[i].s;
  }
  sort(d,d+n,cmp);
  if(k!=1){
  printf("\n");
  }
  printf("Case #%d\n",k++);
  for(i=0;i<n;i++){
  if(i>=1&&d[i].time==d[i-1].time)
    d[i].num=d[i-1].num;
  else 
    d[i].num=i+1;


    printf("%s %d\n",d[i].name,d[i].num);
  }
  }
return 0;
}   注意输出格式

0 0
原创粉丝点击