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:
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 <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 inline ll read(){ 5 int x=0,f=1;char ch=getchar(); 6 while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} 7 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 8 return x*f; 9 } 10 11 /***********************************************************/ 12 13 const int maxn = 1e6+7; 14 15 struct Time{ 16 int h, m, s; 17 }Max, Min; 18 19 int Maxid; 20 int Minid; 21 22 struct node{ 23 char Name[55]; 24 Time in, out; 25 }a[maxn]; 26 27 void sw(Time &x, Time &y){ 28 x.h = y.h; x.m = y.m; x.s = y.s; 29 } 30 31 int main(){ 32 int t; t = read(); 33 Max.h = -1; Min.h = 25; 34 Max.m = Max.s = Min.m = Min.s = 0; 35 for(int i = 0;i < t;i++){ 36 scanf("%s", a[i].Name); 37 38 scanf("%d:%d:%d", &a[i].in.h, &a[i].in.m, &a[i].in.s); 39 if(Min.h > a[i].in.h){ 40 sw(Min, a[i].in), Minid = i; 41 } 42 else if(Min.h == a[i].in.h){ 43 if(Min.m > a[i].in.m){ 44 sw(Min, a[i].in), Minid = i; 45 } 46 else if(Min.m == a[i].in.m){ 47 if(Min.s > a[i].in.s) sw(Min, a[i].in), Minid = i; 48 } 49 } 50 51 scanf("%d:%d:%d", &a[i].out.h, &a[i].out.m, &a[i].out.s); 52 if(Max.h < a[i].out.h){ 53 sw(Max, a[i].out), Maxid = i; 54 } 55 else if(Max.h == a[i].out.h){ 56 if(Max.m < a[i].out.m){ 57 sw(Max, a[i].out), Maxid = i; 58 } 59 else if(Max.m == a[i].out.m){ 60 if(Max.s < a[i].out.s) sw(Max, a[i].out), Maxid = i; 61 } 62 } 63 } 64 printf("%s %s\n", a[Minid].Name, a[Maxid].Name); 65 return 0; 66 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步