hdu-2115I Love This Game201308022033

I Love This Game

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


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
為傑沉倫
 

 

Source
这道题的思路就是比较时间让后用冒泡排序,一定要注意输出格式的问题,两个case间有一个空行,空行一定在case前,不能是在数据输出结束后输出空行
这是第一次用结构体
#include
#include
struct play
{char name[50];
 char time[50];
 //int  rank;
}pl[20];
int main()
{
 int n,i,j,t=0,k,m=0;
 char maxn[50],maxt[50];
  while(scanf("%d",&n)&&n!=0)
 {
   t++;
   for(i=0;i
   {scanf("%s%s",pl[i].name,pl[i].time);}
   if(m!=0)printf("\n");
   for(j=1;j<=n-1;j++)
      for(i=0;i<=n-j-1;i++)
         if(strcmp(pl[i].time,pl[i+1].time)>0)
   {        strcpy(maxt,pl[i].time);
             strcpy(pl[i].time,pl[i+1].time);
             strcpy(pl[i+1].time,maxt);
             strcpy(maxn,pl[i].name);
             strcpy(pl[i].name,pl[i+1].name);
             strcpy(pl[i+1].name,maxn);
            }
   printf("Case #%d\n",t);
   for(i=0;i
   //{pl[i].rank=i+1;//k=strcmp(time[i+1],time[i+2]);
   if(strcmp(pl[i].time,pl[i+1].time)==0)
   {
   printf("%s %d\n",pl[i].name,i+1);
   printf("%s %d\n",pl[i+1].name,i+1);
    i++;}
    else
    printf("%s %d\n",pl[i].name,i+1);//i);
   //}
   //printf("\n");
m++;
}
return 0;
}
这个是用数组做的,将时间转换了一下,直接比较时间用strcmp也可以
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,n,a[20],b[20],s[20]={0},x,w=0,m=1;
    char c[20][50],y[50];
    while(scanf("%d",&n)&&n)
    {
        for(i=0;i<n;i++)
        {
            scanf("%s %d:%d",c[i],&a[i],&b[i]);
            s[i]=a[i]*1000+b[i];
        }
        if(w!=0)printf("\n");      //这句应该放在这,题目没看懂,郁闷死了!
        for(j=1;j<n;j++)
            for(i=1;i<n;i++)
                if(s[i]<s[i-1])
                {
                    x=s[i];
                    s[i]=s[i-1];
                    s[i-1]=x;
                    strcpy(y,c[i]);
                    strcpy(c[i],c[i-1]);
                    strcpy(c[i-1],y);
                }
        printf("Case #%d\n",m);
        for(i=0;i<n;i++)
        {
            if(s[i]==s[i+1])
            {
                printf("%s %d\n",c[i],i+1);
                printf("%s %d\n",c[i+1],i+1);
                i++;
            }
            else printf("%s %d\n",c[i],i+1);
        }
  //if(w!=0)printf("\n");
        w++;
        m++;
    }
    return 0;
}

转载于:https://www.cnblogs.com/dhp2915783/p/3233448.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值