HDU 1234 (浙大计算机研究生复试上机考试-2005年) 开门人和关门人 (水) 开门人和关门人
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11133 Accepted Submission(s): 5667
Total Submission(s): 11133 Accepted Submission(s): 5667
Problem Description
每天第一个到机房的人要把门打开。最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请依据记录找出当天开门和关门的人。
到、签离记录,请依据记录找出当天开门和关门的人。
Input
測试输入的第一行给出记录的总天数N ( > 0 )。以下列出了N天的记录。
每天的记录在第一行给出记录的条目数M ( > 0 )。以下是M行。每行的格式为
证件号码 签到时间 签离时间
当中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
每天的记录在第一行给出记录的条目数M ( > 0 )。以下是M行。每行的格式为
证件号码 签到时间 签离时间
当中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
Output
对每一天的记录输出1行,即当天开门和关门人的证件号码。中间用1空格分隔。
注意:在裁判的标准測试输入中,全部记录保证完整。每一个人的签到时间在签离时间之前,
且没有多人同一时候签到或者签离的情况。
Sample Input
3
1
ME3021112225321 00:00:00 23:59:59
2
EE301218 08:05:35 20:56:35
MA301134 12:35:45 21:40:42
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output
ME3021112225321 ME3021112225321
EE301218 MA301134
SC3021234 CS301133
Source
水题。不解释了。就是简单的字符串应用。
AC代码:
#include <iostream> #include <cstdio> #include <string> #include <algorithm> using namespace std; struct man { string id, st, et; //人的编号。签到时间。签退时间 }; man m[10005]; bool cmp1(man a, man b){ int x = (a.st[0]-'0')*10 + (a.st[1]-'0'); int xx = (a.st[3]-'0')*10 + (a.st[4]-'0'); int xxx = (a.st[6]-'0')*10 + (a.st[7]-'0'); int y = (b.st[0]-'0')*10 + (b.st[1]-'0'); int yy = (b.st[3]-'0')*10 + (b.st[4]-'0'); int yyy = (b.st[6]-'0')*10 + (b.st[7]-'0'); if(x==y && xx==yy) return xxx < yyy; else if(x==y) return xx < yy; return x < y; } bool cmp2(man a, man b){ int x = (a.et[0]-'0')*10 + (a.et[1]-'0'); int xx = (a.et[3]-'0')*10 + (a.et[4]-'0'); int xxx = (a.et[6]-'0')*10 + (a.et[7]-'0'); int y = (b.et[0]-'0')*10 + (b.et[1]-'0'); int yy = (b.et[3]-'0')*10 + (b.et[4]-'0'); int yyy = (b.et[6]-'0')*10 + (b.et[7]-'0'); if(x==y && xx==yy) return xxx > yyy; else if(x==y) return xx > yy; return x > y; } int main(){ // freopen("in.txt", "r", stdin); int t, n; scanf("%d", &t); while(t--){ scanf("%d", &n); for(int i=0; i<n; i++) cin >> m[i].id >> m[i].st >> m[i].et; sort(m, m+n, cmp1); cout << m[0].id<<" "; sort(m, m+n, cmp2); cout << m[0].id << endl; } return 0; }