当前位置:网站首页>1006 sign in and sign out (25 points) (PAT class a)
1006 sign in and sign out (25 points) (PAT class a)
2022-07-04 19:36:00 【Acacia moon tower】
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
The main idea of the topic : Here you are. n Time for individuals to enter and leave the room , Let you find the number of the first person to enter and the last person to leave . A stupid way is used here , But fortunately, it's solved .
#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;
}
边栏推荐
- 函数式接口
- FPGA timing constraint sharing 01_ Brief description of the four steps
- Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
- C# 使用StopWatch测量程序运行时间
- Educational Codeforces Round 22 E. Army Creation
- Shell programming core technology "I"
- 1008 Elevator(20 分)(PAT甲级)
- Shell 编程核心技术《三》
- Technologie de base de la programmation Shell IV
- Opencv functions and methods related to binary threshold processing are summarized for comparison and use
猜你喜欢

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

Stream流

The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize

一文掌握数仓中auto analyze的使用

Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?

PolyFit软件介绍

node_ Exporter deployment

Hough transform Hough transform principle
Summary and sorting of 8 pits of redis distributed lock

Oracle with as ora-00903: invalid table name multi report error
随机推荐
西门子HMI下载时提示缺少面板映像解决方案
2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
Summary and sorting of 8 pits of redis distributed lock
An example of multi module collaboration based on NCF
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
TCP两次挥手,你见过吗?那四次握手呢?
The 300th weekly match of leetcode (20220703)
In flinksql, in addition to data statistics, is the saved data itself a state
测试工程师如何“攻城”(下)
FTP, SFTP file transfer
1005 Spell It Right(20 分)(PAT甲级)
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
指定输出的字符集
如何使用Async-Awati异步任务处理代替BackgroundWorker?
node_ Exporter deployment
Mysql database basic operation -ddl | dark horse programmer
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
Unity editor extends C to traverse all pictures in folders and subdirectories
26. Delete the duplicate item C solution in the ordered array