zoukankan      html  css  js  c++  java
  • I Love This Game-杭电-2115

    Love This Game

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

    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

    解题思路:

    1、  用结构体,排序。注意名字与时间相对应。

    程序:

    #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)   //判断是否和前一名一样。一样则名次一样

                {

                 c[i]=c[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

                {

                  c[i]=c[i-1]+1+t;

                  t=0;

                }

             }

                   if(k!=1)                                           //和题目要求的格式一样,每两个case之间空一行

                          printf(" ");

             printf("Case #%d ",k);

             for(i=0;i<n;i++)

             {

              printf("%s %d",boy[i].name,c[i]);

              printf(" ");

             }

             //printf(" ");

        }

        return 0;

    }

  • 相关阅读:
    ES6 | 关于class类 继承总结
    ES6 | class类的基本语法总结
    开发辅助 | 阿里图标库iconfont入门使用
    JS基本功 | JavaScript专题之数组 方法总结
    前端模块化 | 解读JS模块化开发中的 require、import 和 export
    IOS开发中UITableView和UITableViewCell的几种样式
    SSM项目的搭建
    Linux离线安装Docker
    Http项目转Https项目
    SpringBoot项目的搭建
  • 原文地址:https://www.cnblogs.com/zhouhongweihpu/p/3233054.html
Copyright © 2011-2022 走看看