PAT 1006 Sign In and Sign Out
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
思路#
1 #include <iostream> 2 #include <string> 3 #include <stdio.h> 4 #include <algorithm> 5 6 using namespace std; 7 8 struct Node 9 { 10 string name; 11 int inH, inM, inS; //进入的时、分、秒 12 int outH, outM, outS; //出去的时、分、秒 13 }node[100000]; 14 15 bool cmp1(Node a, Node b) 16 { 17 if(a.inH != b.inH) 18 return a.inH < b.inH; 19 if(a.inM != b.inM) 20 return a.inM < b.inM; 21 if(a.inS != b.inS) 22 return a.inS < b.inS; 23 return true; 24 } 25 26 bool cmp2(Node a, Node b) 27 { 28 if(a.outH != b.outH) 29 return a.outH > b.outH; 30 if(a.outM != b.outM) 31 return a.outM > b.outM; 32 if(a.outS != b.outS) 33 return a.outS > b.outS; 34 return true; 35 } 36 37 int main() 38 { 39 int m; 40 cin >> m; 41 for(int i = 0; i < m; ++i) 42 { 43 cin >> node[i].name; 44 scanf("%d:%d:%d %d:%d:%d", &node[i].inH, &node[i].inM, &node[i].inS, 45 &node[i].outH, &node[i].outM, &node[i].outS); 46 } 47 48 sort(node, node+m, cmp1); 49 cout << node[0].name << ' '; 50 sort(node, node+m, cmp2); 51 cout << node[0].name; 52 53 54 55 return 0; 56 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南