HDU,2215,I Love This Game

来源:互联网 发布:淘宝如何编辑宝贝分类 编辑:程序博客网 时间:2024/06/11 08:21

I Love This Game

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


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>

struct player

{

    char name[20];

    int time;

};

int main()

{

    struct player a[15];

    int n,i,j,k,temp,times;

    char tstr[20];

    times=0;

    if (scanf("%d",&n),n==0) return 0;

    do

    {

        for (i=1;i<=n;i++)

        {

            scanf("%s%d:%d",&a[i].name,&a[i].time,&k);

            a[i].time=a[i].time*60+k;

        }

        for (i=1;i<=n-1;i++)

            for (j=i+1;j<=n;j++)

                if (a[i].time>a[j].time||(a[i].time==a[j].time && strcmp(a[i].name,a[j].name)>0))

                {

                    temp=a[i].time;

                    a[i].time=a[j].time;

                    a[j].time=temp;

                    strcpy(tstr,a[i].name);

                    strcpy(a[i].name,a[j].name);

                    strcpy(a[j].name,tstr);

                }

        printf("Case #%d\n",++times);

        k=1;

        for (i=1;i<=n;i++)

        {

            if (a[i].time!=a[i-1].time)

                k=i;

            printf("%s %d\n",a[i].name,k);

 

        }

        if (scanf("%d",&n),n)

            puts("");

        else return 0;

    }while (1);

    return 0;

}

因为这道题在排序交换时需要在原来的条件a[i].time>a[j].time 之外附加一个条件(a[i].time==a[j].time && strcmp(a[i].name,a[j].name)>0)在输出时使用if (a[i].time!=a[i-1].time) k=i;的语句完成
原创粉丝点击