HDU 2115

简介: I Love This Game Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3593    Accepted Submission(...

I Love This Game

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


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
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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct DATA
{
    char name[50];
    char time[10];
}DATA;
DATA ch[12];
int cmp(const void *a,const void *b)
{
    if(strcmp((*(DATA *)a).time,(*(DATA *)b).time))
        return strcmp((*(DATA *)a).time,(*(DATA *)b).time);
    return strcmp((*(DATA *)a).name,(*(DATA *)b).name);
}        
int main()
{
    int num;
    int i,j,k;
     k=1;
    while(scanf("%d%*c",&num),num)
    {
        if(1!=k)
            printf("\n");//每组测试用例之间有空行 
        memset(ch,0,sizeof(ch));
        for(i=0;i<num;i++)//使用qsort最好从0开始 ,或者qsort(ch+1,……),不过没试过 
            scanf("%s %s",ch[i].name,ch[i].time);
        qsort(ch,num,sizeof(DATA),cmp);
        printf("Case #%d\n",k);
        printf("%s 1\n",ch[0].name);
        k++;
        for(i=1,j=0;i<num;i++)
        {   
            if(strcmp(ch[i].time,ch[i-1].time)==0)
                j++;
            else 
                j=0;
            printf("%s %d\n",ch[i].name,i+1-j);
        }
        //printf("\n");//不能加在这,否则最后一行会多一行空行 
    }
    return 0;
}
            
        
        
        
    

 

目录
相关文章
|
算法 Java
HDU 2084 数塔
在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?
172 0
HDU2203亲和串
博客水平见水平......目前阶段就是这么菜,我会好好努力的!毕业直接拿到阿里offer!
1227 0
|
算法 Java 人工智能
|
人工智能
|
人工智能 Java
HDU 1257
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4182    Accepted Submission(s): 1528 ...
780 0