1006 Sign In and Sign Out
Statement
Metadata
- 作者: CHEN, Yue
- 单位: 浙江大学
- 代码长度限制: 16 KB
- 时间限制: 400 ms
- 内存限制: 64 MB
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
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
Sample Output
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, max = INT_MIN, min = INT_MAX, a, b, c, tot1, tot2, d, e, f;
cin >> n;
string s_max = "", s_min = "", s;
for (i = 0; i < n; i++) {
cin >> s;
scanf("%d:%d:%d", &a, &b, &c);
scanf("%d:%d:%d", &d, &e, &f);
tot1 = a * 3600 + b * 60 + c, tot2 = d * 3600 + e * 60 + f;
if (tot2 > max) {
max = tot2;
s_max = s;
}
if (tot1 < min) {
min = tot1;
s_min = s;
}
}
cout << s_min << " " << s_max << endl;
}