0
点赞
收藏
分享

微信扫一扫

hdu1234 开门人和关门人 (等价转换)



开门人和关门人


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12319    Accepted Submission(s): 6237


Problem 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


Source

​​浙大计算机研究生复试上机考试-2005年​​


Recommend

JGShining   |   We have carefully selected several similar problems for you:   ​​1228​​​  ​​​1236​​​  ​​​1235​​​  ​​​1237​​​  ​​​1230​​ 

​​Statistic​​ | ​Submit​​ | ​Discuss​​ | ​Note​

这道题,就是找最开始开门的人,和最后关门的人,所以我们只要两个排序就行,一个是找最早进来的人,一个找最晚离开的人。

当然这道题如果我们按照小时分钟秒排序,会很麻烦。所以我们可以把小时,分钟全部换算成秒来进行计算。

具体看代码:

#include <stdio.h>
#include <algorithm>
using namespace std;
struct node
{
char str[20];
int star,end;
}c[1000];
bool cmp1(node x,node y)
{
return x.star<y.star;
}
bool cmp2(node x,node y)
{
return x.end>y.end;
}
int main()
{
int ncase,n;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int x1,x2,x3;
scanf("%s %d:%d:%d",c[i].str,&x1,&x2,&x3);
c[i].star=x3+x2*60+x1*3600;
scanf("%d:%d:%d",&x1,&x2,&x3);
c[i].end=x3+x2*60+x1*3600;
}
sort(c,c+n,cmp1);
printf("%s ",c[0].str);
sort(c,c+n,cmp2);
printf("%s\n",c[0].str);
}
return 0;
}



举报

相关推荐

0 条评论