zoey
点击国内主页可以让浏览速度加快哦 ~ !

关于HDOJ 1234题(开门人和关门人) 的理解(C/C++)

2019-08-12 hdoj 字符串 统计 时间比较 浙大计算机研究生复试上机考试-2005年
Word count: 872 | Reading time: 4min

    水题,但是一开始直接拿数组装超内存了,后面改成while循环内的两两比较就没事了(因为只用统计一个最大时间,一个最小时间),不过AC代码不够简洁,有更简单明了的同学的话欢迎分享一下下




题目描述:开门人和关门人

开门人和关门人
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description
  每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请根据记录找出当天开门和关门的人。

Input
  测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。
每天的记录在第一行给出记录的条目数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

Author
  Ignatius.L

Source
  浙大计算机研究生复试上机考试-2005年

原题链接

More info:Question

Accepted代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<string>
using namespace std;
const int maxn = 2;
typedef struct node {
string nameID;
int a_h, a_m, a_s;
int l_h, l_m, l_s;
};
node arrive_, leave_;
void cmp_a(node& a, node& b) {
if (a.a_h < b.a_h) { arrive_ = a; return; }
if (a.a_h > b.a_h) { arrive_ = b; return; }

if (a.a_h == b.a_h && a.a_m < b.a_m) { arrive_ = a; return; }
if (a.a_h == b.a_h && a.a_m > b.a_m) { arrive_ = b; return; }

if (a.a_h == b.a_h && a.a_m == b.a_m && a.a_s < b.a_s) { arrive_ = a; return; }
if (a.a_h == b.a_h && a.a_m == b.a_m && a.a_s > b.a_s) { arrive_ = b; return; }

return;
}
void cmp_l(node& a, node& b) {
if (a.l_h > b.l_h) { leave_ = a; return; }
if (a.l_h < b.l_h) { leave_ = b; return; }

if (a.l_h == b.l_h && a.l_m > b.l_m) { leave_ = a; return; }
if (a.l_h == b.l_h && a.l_m < b.l_m) { leave_ = b; return; }

if (a.l_h == b.l_h && a.l_m == b.l_m && a.l_s > b.l_s) { leave_ = a; return; }
if (a.l_h == b.l_h && a.l_m == b.l_m && a.l_s < b.l_s) { leave_ = b; return; }

return ;
}
node stu[maxn];
int t, n;
int main()
{
char tmp;
cin >> t;
while (t--) {
cin >> n;
int i = 0;
cin >> stu[i].nameID >> stu[i].a_h >> tmp >> stu[i].a_m >> tmp >> stu[i].a_s >> stu[i].l_h >> tmp >> stu[i].l_m >> tmp >> stu[i].l_s;
arrive_ = leave_ = stu[0];
while (--n) {
i = 1;
cin >> stu[i].nameID >> stu[i].a_h >> tmp >> stu[i].a_m >> tmp >> stu[i].a_s >> stu[i].l_h >> tmp >> stu[i].l_m >> tmp >> stu[i].l_s;
cmp_a(arrive_,stu[1]);
cmp_l(leave_,stu[1]);
}
cout << arrive_.nameID << " " << leave_.nameID;
cout << endl;
}
return 0;
}

参考博客

Author: Zoey

Link: https://zoey1038569979.github.io/2019/08/12/hdoj1234/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
关于HDOJ 1235题(统计同成绩学生人数) 的理解(C/C++)
NextPost >
关于HDOJ 1219题(AC Me) 的理解(C/C++)
CATALOG
  1. 1. 题目描述:开门人和关门人
  2. 2. 原题链接
  3. 3. Accepted代码
  4. 4. 参考博客