2道水题

来源:互联网 发布:weedfs java 编辑:程序博客网 时间:2024/04/29 23:19

2道类似的题,放在一起看看比较比较吧


Description

每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请根据记录找出当天开门和关门的人。

Input
测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为

证件号码 签到时间 签离时间

其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。

Output
对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,
且没有多人同时签到或者签离的情况。

Sample Input
3
1
ME3021112225321 00:00:00 23:59:59
2
EE301218 08:05:35 20:56:35
MA301134 12:35:45 21:40:42
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

Sample Output
ME3021112225321 ME3021112225321
EE301218 MA301134

SC3021234 CS301133


#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;struct person{char name[1000];char start[8];char end [8];};int cmp1(person a,person b){return (strcmp(a.start,b.start)<=0);}int cmp2(person a,person b){return (strcmp(a.end,b.end)>=0);}int main(){person a[100],b,c;int t;scanf("%d",&t);while(t--){int n,i;scanf("%d",&n);for(i=0;i<n;i++){scanf("%s %s %s",&a[i].name,&a[i].start,&a[i].end);}sort(a,a+n,cmp1);b=a[0];sort(a,a+n,cmp2);c=a[0];printf("%s %s\n",b.name,c.name);}}



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 <iostream>#include <cstring>#include <algorithm>using namespace std;struct node{    char na[10];    int m,s;}p[11];bool cmp(node a,node b){    if(a.m==b.m&&a.s==b.s)    return strcmp(a.na,b.na)<0;    else if(a.m==b.m)    return a.s<b.s;    return a.m<b.m;}int main(){    bool ok=0;    int i,j,n,ca=1,r,sum;    while(cin>>n&&n!=0)    {        if(ok)        cout<<endl;        ok=1;        for(i=0;i<n;i++)        {            scanf("%s %d:%d",p[i].na,&p[i].m,&p[i].s);        }        r=1,sum=1;        sort(p,p+n,cmp);        cout<<"Case #"<<ca++<<endl;        for(i=0;i<n;i++)        {            if(i!=0&&(p[i].m!=p[i-1].m||p[i].s!=p[i-1].s))            r=sum;            cout<<p[i].na<<" "<<r<<endl;            sum++;        }    }    return 0;}


0 0
原创粉丝点击