I Love This Game
Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4664    Accepted Submission(s): 1599


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
HDU 2007-10 Programming Contest_WarmUp

思路分析:这题排一下顺序,排序时关键是,在对在对时间排序时,要让排完序的时间与人名对上,
解决的方法是在用冒泡排时间顺序的时候,也把人名交换一下。

输出时应注意当时间一样时,要把人名也要排一下序
法一:#include<stdio.h>
struct stu
{
 char name[30];
 char shijian[10];
}boy[12];
int main()
{
    int n,m,i,j=0,k=0,t,c[12];
    char a[10],b[30];
    while(scanf("%d",&n)&&n!=0)
    {
      k++;
      for(i=0;i<n;i++)
       scanf("%s %s",boy[i].name,boy[i].shijian);
       for(i=1;i<=n;i++)
        for(j=0;j<n-i;j++)
         {
           if(strcmp(boy[j].shijian,boy[j+1].shijian)>=0)
            {
             strcpy(a,boy[j+1].shijian);
             strcpy(boy[j+1].shijian,boy[j].shijian);
             strcpy(boy[j].shijian,a);
             strcpy(b,boy[j+1].name);
             strcpy(boy[j+1].name,boy[j].name);
             strcpy(boy[j].name,b);
            }
         }
         c[0]=1;t=0;
         for(i=1;i<n;i++)
         {
           if(strcmp(boy[i].shijian,boy[i-1].shijian)==0)
            {
             a[i]=a[i-1];
             t++;
             if(strcmp(boy[i].name,boy[i-1].name)<0)
             {
              strcpy(b,boy[i].name);
              strcpy(boy[i].name,boy[i-1].name);
              strcpy(boy[i-1].name,b);
              }
            }
            else
            {
              a[i]=a[i-1]+1+t;
              t=0;
            }
         }
   if(k!=1)
    printf("\n");
         printf("Case #%d\n",k);
         for(i=0;i<n;i++)
         {
          printf("%s %d",boy[i].name,a[i]);
          printf("\n");
         }
         //printf("\n");
    }
    return 0;
}
*/
法二:
#include "stdio.h"
#include "string.h"
#include "malloc.h"
int main()
{int n,i,j;
  int   q=0;
  char a1[6];
 char a2[20];
 int c[12]={0};
 char (*a)[20],(*b)[6];
while( scanf("%d",&n),n)
 {//char (*a)[20],(*b)[6];
 //char a1[6];
// char a2[20];
 //int c[12]={0};

 int r=1,t;
 a=(char (*)[20])malloc(sizeof(char)*n*20);
 b=(char (*)[6])malloc(sizeof(char)*n*6);
// c=(char (*)[6])malloc(sizeof(char)*n*6);
 for(i=0;i<n;i++)
 {scanf("%s %s",a[i],b[i]);
    }
 /*for(i=0;i<n;i++)
 strcpy(c[i],b[i]);*/
 
 strcpy(a2,a[0]);
 
    for(i=1;i<n;i++)
    for(j=0;j<n-i;j++)
     {
      if(strcmp(b[j],b[j+1])>0)
        {   //k=j;
         strcpy(a1,b[j]);
         strcpy(a2,a[j]);
         strcpy(b[j],b[j+1]);
         strcpy(a[j],a[j+1]);
         strcpy(b[j+1],a1);
         strcpy(a[j+1],a2);
         }
      }
   
     
    q++;
      if(q>1)
     printf("\n");
   // printf("%d   ",q);

        //k++;
     printf("Case #%d\n",q);
    // k++;
    // printf("%s %d\n",a[0],1);
    // k++;

     c[0]=1;t=0;
     for(i=1;i<n;i++)
      { if(strcmp(b[i],b[i-1])==0)
    {  c[i]=c[i-1];
      t++;
   if(strcmp(a[i],a[i-1])<0)
     { strcpy(a2,a[i]);
     strcpy(a[i],a[i-1]);
     strcpy(a[i-1],a2);
   
   }
    //   printf("%s %d\n",a[i],r);
    }
   else
   { c[i]=c[i-1]+1+t;
   t=0;
   }
      }
    
    //  else
     // {  
      //    printf("%s %d\n",a[i],i+1);
     
    //  }

     //  k++;
    //printf("%d   ",k);
    
     for(i=0;i<n;i++)
  printf("%s %d\n",a[i],c[i]);
  } 
  
   return 0;
 }
 

posted on 2013-08-02 15:50  守护生命的绿荷  阅读(242)  评论(0编辑  收藏  举报