当前位置:网站首页>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;
}
边栏推荐
- 2022CoCa: Contrastive Captioners are Image-Text Fountion Models
- MySQL数据库基本操作-DDL | 黑马程序员
- Lex and yacc based lexical analyzer + parser
- Lm10 cosine wave homeopathic grid strategy
- From automation to digital twins, what can Tupo do?
- 请教一下 flinksql中 除了数据统计结果是状态被保存 数据本身也是状态吗
- How test engineers "attack the city" (Part I)
- 数组中的第K个最大元素
- 每日一题(2022-07-02)——最低加油次数
- C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
猜你喜欢

与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用

小发猫物联网平台搭建与应用模型

英特尔集成光电研究最新进展推动共封装光学和光互连技术进步

Use canal and rocketmq to listen to MySQL binlog logs

Pytorch学习(四)

如何使用Async-Awati异步任務處理代替BackgroundWorker?

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

在线文本行固定长度填充工具

神经网络物联网应用技术就业前景【欢迎补充】

整理混乱的头文件,我用include what you use
随机推荐
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Using SSH
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
ftp、sftp文件传输
Don't just learn Oracle and MySQL!
利用策略模式优化if代码【策略模式】
从实时应用角度谈通信总线仲裁机制和网络流控
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
Caché WebSocket
函数式接口
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
Go微服务(二)——Protobuf详细入门
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
How test engineers "attack the city" (Part I)
Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
LeetCode第300场周赛(20220703)
每日一题(2022-07-02)——最低加油次数
MySQL数据库基本操作-DDL | 黑马程序员
偏移量函数及开窗函数
Unity adds a function case similar to editor extension to its script, the use of ContextMenu