I Love This Game

I Love This Game

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


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
 

Author
為傑沉倫
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct p//定义一个struct类型的变量 p
{
    int m;//分钟变量
    int s;//秒变量
    int pai;//这个是标记序号的
    char name[100];//名字
} a[11];
int cmp(p a,p b)
{
    if(a.m!=b.m)//就是当分钟不相同的时候进行的排序
        return a.m<b.m;
    else if(a.s!=b.s)
        return a.s<b.s;
    else
        return strcmp(a.name,b.name)<0;//相同的时候安字典排序进行排列
}
int main()
{
    int n,cas=1;
    while(scanf("%d",&n)&&n)
    {
        getchar();
        if(cas!=1)
            printf("\n");//就是第二个以后就要进行空行了!
        for(int i=0; i<n; i++)
        {
            scanf("%s %d:%d",a[i].name,&a[i].m,&a[i].s);//输入名字,分钟,秒
            getchar();
        }
        sort(a,a+n,cmp);//排序,以下比较关键
        a[0].pai=1;//就是把a[0]的pai记录为1
        for(int i=1; i<n; i++)
        {
            if(a[i].m==a[i-1].m&&a[i].s==a[i-1].s)//如果前后两个序号的时间相同,则这两个序号都设为1
                a[i].pai=a[i-1].pai;//即序号相同
            else a[i].pai=i+1;//否则,序号加一
        }
        printf("Case #%d\n",cas++);
        for(int i=0; i<n; i++)
            printf("%s %d\n",a[i].name,a[i].pai);//输出名字的时候顺便输出序号!
    }
    return 0;
}
我感觉结构体排序还是很简单的,但是却被这一题难住了,因为这一题在排序的时候还要让你标出序号,但是这一个序号不是简单的序号,相同的序号相同,所以我就卡在这里了,看到网上的代码才有所体会!此外
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值