当前位置:网站首页>1006 Sign In and Sign Out(25 分)(PAT甲级)
1006 Sign In and Sign Out(25 分)(PAT甲级)
2022-07-04 17:59:00 【相思明月楼】
Problem Description:
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
题目大意:给你n个人进入和离开房间的时间,让你找最早进入和最晚离开的人的编号。这里用了个笨办法,不过还好解出来了。
#include <iostream>
#include <algorithm>
using namespace std;
struct p{
char id[20];
char bt[20];
char et[20];
};
bool cmp1(struct p a, struct p b) {
int h1, m1, s1;
int h2, m2, s2;
h1 = h2 = m1 = m2 = s1 = s2 = 0;
for(int i = 0; i <= 1; i++) {
h1 = h1*10 + (a.bt[i]-'0');
h2 = h2*10 + (b.bt[i]-'0');
}
for(int i = 3; i <= 4; i++) {
m1 = m1*10 + (a.bt[i]-'0');
m2 = m2*10 + (b.bt[i]-'0');
}
for(int i = 6; i <= 7; i++) {
s1 = s1*10 + (a.bt[i]-'0');
s2 = s2*10 + (b.bt[i]-'0');
}
if(h1 != h2) {
return h1 < h2;
} else {
if(m1 != m2) {
return m1 < m2;
} else {
return s1 < s2;
}
}
}
bool cmp2(struct p a, struct p b) {
int h1, m1, s1;
int h2, m2, s2;
h1 = h2 = m1 = m2 = s1 = s2 = 0;
for(int i = 0; i <= 1; i++) {
h1 = h1*10 + (a.et[i]-'0');
h2 = h2*10 + (b.et[i]-'0');
}
for(int i = 3; i <= 4; i++) {
m1 = m1*10 + (a.et[i]-'0');
m2 = m2*10 + (b.et[i]-'0');
}
for(int i = 6; i <= 7; i++) {
s1 = s1*10 + (a.et[i]-'0');
s2 = s2*10 + (b.et[i]-'0');
}
if(h1 != h2) {
return h1 > h2;
} else {
if(m1 != m2) {
return m1 > m2;
} else {
return s1 > s2;
}
}
}
int main() {
int t;
struct p a[1010];
scanf("%d", &t);
for(int i = 0; i < t; i++) {
scanf("%s%s%s", a[i].id, a[i].bt, a[i].et);
}
sort(a, a+t, cmp1);
printf("%s ", a[0].id);
sort(a, a+t, cmp2);
printf("%s\n", a[0].id);
return 0;
}
边栏推荐
- Caché WebSocket
- FTP, SFTP file transfer
- 安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
- Nebula importer data import practice
- From automation to digital twins, what can Tupo do?
- Other InterSystems%net tools
- sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
- 26. 删除有序数组中的重复项 C#解答
- redis分布式锁的8大坑总结梳理
- The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
猜你喜欢
随机推荐
Don't just learn Oracle and MySQL!
Perfect JS event delegation
信息学奥赛一本通 1336:【例3-1】找树根和孩子
2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
神经网络物联网应用技术学什么
Download the first Tencent technology open day course essence!
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
876. 链表的中间结点
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
“只跑一趟”,小区装维任务主动推荐探索
Nebula importer data import practice
The 300th weekly match of leetcode (20220703)
node_exporter部署
2021 合肥市信息学竞赛小学组
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
1672. Total assets of the richest customers
[release] a tool for testing WebService and database connection - dbtest v1.0
Qt实现界面滑动切换效果
From automation to digital twins, what can Tupo do?




![[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0](/img/4e/4154fec22035725d6c7aecd3371b05.jpg)



