当前位置:网站首页>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;
}
边栏推荐
- Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
- @transactional滥用导致数据源连接池耗尽问题
- ftp、sftp文件传输
- 指定输出的字符集
- 双冒号作用运算符以及命名空间详解
- FTP, SFTP file transfer
- 26. Delete the duplicate item C solution in the ordered array
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- Mysql database basic operation -ddl | dark horse programmer
- Have you guys ever used CDC direct Mysql to Clickhouse
猜你喜欢

OpenCV的二值化处理函数threshold()详解

Hough Transform 霍夫变换原理

Online text line fixed length fill tool
Some thoughts on whether the judgment point is located in the contour
牛客小白月赛7 谁是神箭手

Stream stream

Bi skills - permission axis

To sort out messy header files, I use include what you use
关于判断点是否位于轮廓内的一点思考

SSRS筛选器的IN运算(即包含于)用法
随机推荐
1011 World Cup Betting (20 分)(PAT甲级)
2019年蜀山区第十五届青少年信息学竞赛
牛客小白月赛7 I 新建 Microsoft Office Word 文档
Wechat reading notes of "work, consumerism and the new poor"
1003 Emergency(25 分)(PAT甲级)
Stream stream
Shell 编程核心技术《二》
Mysql database basic operation -ddl | dark horse programmer
Educational Codeforces Round 22 E. Army Creation
Bi skills - permission axis
1008 Elevator(20 分)(PAT甲级)
Socket programming demo II
Shell 编程核心技术《四》
函数式接口
Introduction to polyfit software
Specify the character set to output
Unity editor extends C to traverse all pictures in folders and subdirectories
Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
26. 删除有序数组中的重复项 C#解答
Leetcode fizzbuzz C # answer