武汉科技大学计算机学院菜鸟杯:I Love This Game.(杭电2115)

来源:互联网 发布:配电网络规划与设计图 编辑:程序博客网 时间:2024/04/28 01:40

I Love This Game

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


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
10Iverson 17:19Bryant 07:03Nash 09:33Wade 07:03Davies 11:13Carter 14:28Jordan 29:34James 20:48Parker 24:49Kidd 26:460
 

Sample Output
Case #1Bryant 1Wade 1Nash 3Davies 4Carter 5Iverson 6James 7Parker 8Kidd 9Jordan 10
 
 
/*本题需要注意的是输出格式,PE是常犯的错误,只要把时间转换一下就行了,注意时间一样时按字符串排序*/#include<stdio.h>#include<string.h>int main(){    long int a[10];    int i,j,k,n,b[10][2],t,s2[10],h;    char s[10][50],s1[50];    k=0;    h=1;    while(scanf("%d",&n)&&n!=0)    {        k++;        if(h==0) printf("\n");        h=0;        for(i=0;i<n;i++)        {            a[i]=0;            s2[i]=1;            scanf("%s",s[i]);            scanf("%d:%d",&b[i][0],&b[i][1]); /*用整型输入的时候注意冒号,用字符串则另做处理*/        }        for(i=0;i<n;i++)        {            a[i]=b[i][0]*60+b[i][1];     /*将时间转化成数字*/        }        for(i=0;i<n;i++)        {            for(j=0;j<n-i-1;j++)            {                if(a[j]>a[j+1])                {                    t=a[j];                    a[j]=a[j+1];                    a[j+1]=t;                    strcpy(s1,s[j]);       /*字符串按照整型数据的排序而跳动*/                    strcpy(s[j],s[j+1]);                    strcpy(s[j+1],s1);                }            }        }        printf("Case #%d\n",k);        for(i=1;i<n;i++)        {            if(a[i]==a[i-1]) s2[i]=s2[i-1];         /*将转化出来的整型数组中的元素排序并标号*/            else s2[i]=i+1;        }        for(i=0;i<n;i++)        {            printf("%s",s[i]);            printf(" %d\n",s2[i]);        }    }    return 0;}
 
 
 
 
 
 
另一种解法,用结构做,不管懂不懂都可以看看
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <set>#include <map>#include <queue>using namespace std;/*freopen("input.txt",  "r", stdin);  //读数据freopen("output.txt", "w", stdout); //注释掉此句则输出到控制台*/struct st{    char name[20];    int time;    int num;}hxf[15];bool cmp(st a,st b){    return a.time<b.time;}int main(){    int i,j,n;    int ca=0;    while(scanf("%d",&n)&&n!=0)    {        int a,b;        for(i=0;i<n;i++)        {            scanf("%s %d:%d",hxf[i].name,&a,&b);            hxf[i].time=a*60+b;        }        sort(hxf,hxf+n,cmp);        for(i=0;i<n;i++)            hxf[i].num=i+1;        for(i=1;i<n;i++)        {            if(hxf[i].time==hxf[i-1].time)                hxf[i].num=hxf[i-1].num;        }        if(ca>0)            printf("\n");        printf("Case #%d\n",++ca);        for(i=0;i<n;i++)        {            printf("%s %d\n",hxf[i].name,hxf[i].num);        }    }    return 0;}

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

原创粉丝点击