HDU--2115 I Love This Game

本文介绍了一种解决篮球技巧挑战赛排名问题的算法。通过输入参赛者完成比赛的时间,算法能够输出排名,并处理时间相同的情况,确保输出的排名准确且符合规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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. 

<span style="font-size:14px;">#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct player{
    char name[30];
    char time[10];
}a[15];
int temp(player a,player b){
    if(strcmp(a.time,b.time)==0){
        if(strcmp(a.name,b.name)<0)
            return 1;
        else return 0;
    }
    else if(strcmp(a.time,b.time)<0)
        return 1;
    else return 0;
}
int main(){
    int n;
    int Case=0;
    while(scanf("%d",&n)==1&&n!=0){
        Case++;
        if(Case==1)
            printf("Case #%d\n",Case);
        else printf("\nCase #%d\n",Case);
        for(int i=0;i<n;i++)
            scanf("%s%s",a[i].name,a[i].time);
        sort(a,a+n,temp);
        printf("%s 1\n",a[0].name);
        for(int i=1;i<n;i++){
            if(strcmp(a[i].time,a[i-1].time)==0)
                printf("%s %d\n",a[i].name,i);
            else printf("%s %d\n",a[i].name,i+1);
        }
    }
}
</span>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值