1006 Sign In and Sign Out (25)(25 分)
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.
Input Specification:
Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:
ID_number Sign_in_time Sign_out_time
where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.
Output Specification:
For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.
Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.
Sample Input:
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output:
SC3021234 CS301133
# include <iostream>
# include <cstring>
using namespace std;
const int maxn = 1e5;
struct node{
char id[20];
int in_hour, in_minute, in_second;
int out_hour, out_minute, out_second;
node(){
memset(id, 0, sizeof(id));
in_hour = in_minute = in_second = maxn;
out_hour = out_minute = out_second = 0;
}
}fale[maxn], unlock, lock;
void cmp(node a){
if(a.in_hour < unlock.in_hour) unlock = a;
else if(a.in_hour == unlock.in_hour){
if(a.in_minute < unlock.in_minute) unlock = a;
else if(a.in_minute == unlock.in_minute){
if(a.in_second < unlock.in_second) unlock = a;
}
}
if(a.out_hour > lock.out_hour) lock = a;
else if(a.out_hour == lock.out_hour){
if(a.out_minute > lock.out_minute) lock = a;
else if(a.out_minute == lock.out_minute) {
if(a.out_second > lock.out_second) lock = a;
}
}
}
int main(){
// freopen("C:\\1.txt", "r", stdin);
int m;
scanf("%d", &m);
for(int i = 0; i < m; i++){
scanf("%s %d:%d:%d %d:%d:%d", fale[i].id,
&fale[i].in_hour, &fale[i].in_minute, &fale[i].in_second,
&fale[i].out_hour, &fale[i].out_minute, &fale[i].out_second);
cmp(fale[i]);
}
printf("%s %s\n", unlock.id, lock.id);
return 0;
}
本文介绍了一个通过记录人员进出时间来确定当天第一个进入及最后一个离开者的程序设计问题。输入包含若干人员的进出时间记录,输出则为第一个解锁门与最后一个锁门者的ID号。
348

被折叠的 条评论
为什么被折叠?



