PAT - 甲级 - 1006. Sign In and Sign Out (25
来源:互联网 发布:会计网络培训 编辑:程序博客网 时间:2024/05/16 14:27
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
#include<iostream>#include<cstdio>#include<string>#include<algorithm>using namespace std;struct person{string name;int hour1;int minute1;int second1;int hour2;int minute2;int second2;};bool cmp1(person p1,person p2){if(p1.hour1!=p2.hour1){return p1.hour1<p2.hour1;}else if(p1.minute1!=p2.minute1){return p1.minute1<p2.minute1;}else{return p1.second1<p2.second1;}}bool cmp2(person p1,person p2){if(p1.hour2!=p2.hour2){return p1.hour2<p2.hour2;}else if(p1.minute2!=p2.minute2){return p1.minute2<p2.minute2;}else{return p1.second2<p2.second2;}}int main(){int n;cin>>n;person p[n];for(int i=0 ;i<n ;i++){cin>>p[i].name;scanf("%d:%d:%d%d:%d:%d",&p[i].hour1,&p[i].minute1,&p[i].second1,&p[i].hour2,&p[i].minute2,&p[i].second2);}sort(p,p+n,cmp1);//寻找最早到达的人 cout<<p[0].name<<" ";sort(p,p+n,cmp2);//寻找最晚离开的人 cout<<p[n-1].name<<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 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 (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
- [PAT-甲级]1006.Sign In and Sign Out
- PAT甲级1006. Sign In and Sign Out
- PAT 甲级 1006. Sign In and Sign Out
- github atom编辑器推介 - 足以替代 sublime
- 切图崽的自我修养-如何合理组织CSS
- Spring Security(13)——session管理
- Mac下安装 RODBC 包问题
- Spring Security(14)——权限鉴定基础
- PAT - 甲级 - 1006. Sign In and Sign Out (25
- 手淘h5适配方案
- Qt学习笔记2
- 跟我学Android之六 布局
- javascript基本知識-w3Schools-2
- Linux字符设备驱动中container_of宏的作用
- Spring Security(15)——权限鉴定结构
- 训练4 习题6
- Spring Security(16)——基于表达式的权限控制