[PAT-甲级]1006.Sign In and Sign Out
来源:互联网 发布:美工刀片的硬度 编辑:程序博客网 时间:2024/05/16 17:27
1006. Sign In and Sign Out (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:3CS301111 15:30:28 17:00:10SC3021234 08:00:00 11:25:25CS301133 21:45:00 21:58:40Sample Output:
SC3021234 CS301133
解题思路:题意让我们从一组乱序的数据中,找到最早到,以及最晚时间走的。也就是考察字符串比较大小,可以直接比较,不需要写重载函数,那就和整数比较大小一样了。考察点:string容器
#include<iostream>#include<string>using namespace std;int main(){int M;string ID_number, Sign_in_time, Sign_out_time;cin>>M;cin>>ID_number>>Sign_in_time>>Sign_out_time;string open_number = ID_number;string close_number = ID_number;string open_time = Sign_in_time;string close_time = Sign_out_time;while(-- M){cin>>ID_number>>Sign_in_time>>Sign_out_time;if(Sign_in_time < open_time){open_time = Sign_in_time;open_number = ID_number;}if(Sign_out_time > close_time){close_time = Sign_out_time;close_number = ID_number;}}cout<<open_number<<" "<<close_number<<endl;return 0;}
- PAT - 甲级 - 1006. Sign In and Sign Out (25
- PAT甲级.1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25) PAT 甲级
- 【PAT甲级】1006. Sign In and Sign Out (25)
- 【PAT甲级】【C++】1006. Sign In and Sign Out (25)
- PAT(甲级)1006. Sign In and Sign Out
- PAT TEST甲级1006. Sign In and Sign Out (25)
- PAT甲级练习1006. Sign In and Sign Out (25)
- PAT甲级1006. Sign In and Sign Out (25)
- PAT甲级1006. Sign In and Sign Out (25)
- PAT 甲级 1006. Sign In and Sign Out
- PAT甲级 1006. Sign In and Sign Out (25)
- [PAT-甲级]1006.Sign In and Sign Out
- PAT甲级1006. Sign In and Sign Out
- PAT 甲级 1006. Sign In and Sign Out
- PAT甲级1006. Sign In and Sign Out (25)
- PAT甲级 1006. Sign In and Sign Out (25)
- PAT 甲级 1006. Sign In and Sign Out (25)
- 通过grep -f 比较两个文件的不同
- 怎么学好PHP
- SolidWorks v2017 SP0 Win64 1DVD
- java的静态方法继承问题
- Ketama一致性Hash算法(含Java代码)
- [PAT-甲级]1006.Sign In and Sign Out
- Fragment全解析系列(一):那些年踩过的坑
- Java面试基础——持续更新
- SRM556 Div1Medium LeftRightDigitsGame2
- unsigned和signed的个人体会
- OC与Swift混合使用
- FreeMarker的List的使用
- tomcat报错信息:严重: StandardServer.await: create[8005]:
- h264基本介绍