1006. Sign In and Sign Out (25)
2016-03-07 22:26
513 查看
1006. Sign In and Sign Out (25)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
a464
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>
using namespace std;
int compare(string a, string b)
{
string ha, ma, sa, hb, mb, sb;
ha = a.substr(0,2);
ma = a.substr(3,2);
sa = a.substr(6,2);
hb = b.substr(0,2);
mb = b.substr(3,2);
sb = b.substr(6,2);
if(ha > hb) return 1;
if(hb > ha) return -1;
if(ma > mb) return 1;
if(mb > ma) return -1;
if(sa > sb) return 1;
if(sb > sa) return -1;
return 0; //equal
}
int main()
{
int n;
string id, in_t, out_t;
string lock, unlock;
string max_t, min_t;
max_t = "00:00:00";
min_t = "99:99:99";
cin >> n;
for(int i = 0; i < n; i++){
cin >> id >> in_t >> out_t;
if(compare(in_t, min_t) == -1){
min_t = in_t;
unlock = id;
}
if(compare(out_t, max_t) == 1){
max_t = out_t;
lock = id;
}
}
cout << unlock << " " << lock << endl;
//system("pause");
}
相关文章推荐
- libdvbpsi源码分析(四)PAT表解析/重建
- PAT配置
- 什么是端口复用动态地址转换(PAT) 介绍配置实例
- MikroTik layer7-protocol
- PAT是如何工作的
- PAT 乙级题:1002. 写出这个数 (20)
- PAT (Advanced Level) Practise 1001-1010
- 数据结构学习与实验指导(一)
- PAT Basic Level 1001-1010解题报告
- 1001. 害死人不偿命的(3n+1)猜想
- 1002. 写出这个数
- 1032. 挖掘机技术哪家强
- 1001. 害死人不偿命的(3n+1)猜想 (PAT basic)
- 1002. 写出这个数(PAT Basic)
- 1004. 成绩排名(PAT Basic)
- 1006. 换个格式输出整数(PAT Basic)
- 1007. 素数对猜想(PAT Basic)
- 1008. 数组元素循环右移问题
- 1009. 说反话(PAT Basic)
- 1011. A+B和C(PAT Basic)