zoukankan      html  css  js  c++  java
  • 【ACM】hdu_2115_I Love This Game_201308021517

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


    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

    #include <stdio.h>
    #include <string.h>
    struct rank
    {
     char name[20];
     char time[10];
    };
    int main()
    {
     struct rank s[12];
     int k=1,n;
     while(scanf("%d",&n),n)
     {
      
      int i,j,t,m1,m2,m3=1;
      int a[12]={0};  
      for(i=1;i<=n;i++)
      scanf("%s%s",s[i].name,s[i].time);
      if(k>1) printf(" ");
      for(i=1;i<=n;i++)
      {
       for(j=1;j<=n;j++)
       {
        if(j==i) continue;
        else
        {
         if(strcmp(s[i].time,s[j].time)>0)
         a[i]++;
         if(strcmp(s[i].time,s[j].time)==0)
         if(strcmp(s[i].name,s[j].name)>0)
         a[i]++;
        }
       }
      }
      //for(i=1;i<=n;i++)
      //printf("%d ",a[i]);
       printf("Case #%d ",k);
       for(i=1;i<=n;i++)
       {
        if(a[i]==0)
        {
        printf("%s %d ",s[i].name,1);
        m1=i;m2=1;m3++;
        }
        //printf("%d ",m1);
       }
       t=1;
       while(t<n){
       for(i=1;i<=n;i++)
       {
        if(a[i]==t)
        {
         printf("%s ",s[i].name);
         if(strcmp(s[i].time,s[m1].time)==0)
         {printf("%d ",m2);m3++;}
         else
         {printf("%d ",m3);m2=m3;m3++;}
         m1=i;
        }
       }
       t++;
       }
     k++;
     } 
     return 0;
    }

    //AC

    //网上找的感觉不错的代码,能AC

    //冒泡排序法
    #include<stdio.h>
    struct pp
    {
     char w[20];
     int shi;
     int fen;
     int shijian;
     int paiming;
    };
    struct pp ans[11];
    struct pp temp;
    int main()
    {
     int n,i,j,m=1;
     while(scanf("%d",&n)&&n!=0)
     {
         for(i=0;i<n;i++)
         {
          scanf("%s %d:%d",ans[i].w,&ans[i].shi,&ans[i].fen);
          ans[i].shijian=60*ans[i].shi+ans[i].fen;
         }    
         for(i=0;i<n;i++)
         {
             for(j=0;j<n-1-i;j++)
             {
                 if(ans[j].shijian>ans[j+1].shijian)
                 {
                  temp=ans[j];
                  ans[j]=ans[j+1];
                  ans[j+1]=temp;
                 }//整个结构体互换
             }
          }//冒泡排序
          ans[0].paiming=1;
          for(i=1;i<n;i++)
          {
             if(ans[i-1].shijian==ans[i].shijian)
             ans[i].paiming=ans[i-1].paiming;
             else
             ans[i].paiming=i+1;
          }//排名次
          if(m!=1)
          printf(" ");
          printf("Case #%d ",m++);
          for(i=0;i<n;i++)
          printf("%s %d ",ans[i].w,ans[i].paiming);
          /*
          if(k!=1)printf(" "); 
          printf("Case #%d ",k++);
          for(i=0;i<n;i++) 
          { 
              if(i>=1&&d[i].tim==d[i-1].tim) 
              {d[i].num=d[i-1].num;} 
              else 
              {d[i].num=i+1;} 
              printf("%s %d ",d[i].name,d[i].num); 
          } 
          */
     }
     return 0;
    }

  • 相关阅读:
    【转】折腾好windows 7和windows 2003双系统
    【转】ndis 相关资料
    【转】自己开发程序管理WINDOWS防火墙
    你给信息工程专业本科大一的学生推荐些什么书?
    【转】如何禁止指定IP访问我的计算机
    【转】一个C#写的调用外部进程类
    【转】Crossbow携手微软,全新工具包推进无线传感器应用开发
    【转】RFC整理分类
    【转】国内外物联网技术研究进展
    【链】SmartBits600测试指导书
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3232736.html
Copyright © 2011-2022 走看看