原题
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
题目翻译
每天一开始,第一个签到的人会打开计算机房的门锁,最后一个签退的人会锁上门。根据签到和签退记录,您应该找出当天开锁和锁门的人。
输入规范:
每个输入文件包含一个测试用例。每个案例包含一天的记录。案例以一个正整数 M(即记录总数)开头,然后是 M 行,每行的格式为
ID_number 签入时间 签出时间
其中时间的格式为 HH:MM:SS,ID_number 是不超过 15 个字符的字符串。
输出规范:
对于每个测试用例,在一行中输出当天开锁和锁门人员的 ID 编号。两个 ID 号之间必须用一个空格隔开。
注意:保证记录一致。也就是说,每个人的签入时间必须早于签出时间,并且没有两个人在同一时刻签入或签出。
解题思路
考察字符串处理,c++中字符串可以直接比较大小,直接遍历一遍所有数据秒了。
代码(c++)
#include <bits/stdc++.h>
using namespace std;
int n;
string id, sign_in, sign_out;
string min_id, max_id;
int main(){
cin >> n;
string min_time = "23:59:59", max_time = "00:00:00";
for(int i = 0; i < n; i++){
cin >> id >> sign_in >> sign_out;
if(sign_in < min_time) {
min_time = sign_in;
min_id = id;
}
if(sign_out > max_time){
max_time = sign_out;
max_id = id;
}
}
cout << min_id << " " << max_id << endl;
return 0;
}