PAT 甲级 1006 Sign In and Sign Out
https://pintia.cn/problem-sets/994805342720868352/problems/994805516654460928
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
时间复杂度:$O(N)$
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N; struct Students {
char name[50];
int sh, sm, ss;
int eh, em, es;
long long sTime, eTime;
}students[maxn]; int main() {
scanf("%d", &N);
bool flag = true;
for(int i = 1; i <= N; i ++) {
scanf("%s %d:%d:%d %d:%d:%d", students[i].name, &students[i].sh, &students[i].sm,
&students[i].ss, &students[i].eh, &students[i].em, &students[i].es);
students[i].sTime = students[i].sh * 3600 + students[i].sm * 60 + students[i].ss;
students[i].eTime = students[i].eh * 3600 + students[i].em * 60 + students[i].es;
if(students[i].sTime > students[i].eTime)
flag = false;
} int temp1, temp2;
long long minn = students[1].sTime, maxx = students[1].eTime;
for(int i = 1; i <= N; i ++) {
if(flag) {
if(students[i].sTime <= minn) {
minn = students[i].sTime;
temp1 = i;
}
if(students[i].eTime >= maxx) {
maxx = students[i].eTime;
temp2 = i;
}
}
} printf("%s %s\n", students[temp1].name, students[temp2].name); return 0;
}
PAT 甲级 1006 Sign In and Sign Out的更多相关文章
- PAT 甲级 1006 Sign In and Sign Out (25)(25 分)
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- PAT甲级——1006 Sign In and Sign Out
PATA1006 Sign In and Sign Out At the beginning of every day, the first person who signs in the compu ...
- PAT甲级1006水题飘过
题目分析:由于不存在相同的两个时间(24:00:00和00:00:00不会同时存在),则我们假设两个全局变量存放到达的最早的时间和达到的最晚的时间,设置最早的初值为“23:59:59”,设置最晚的初值 ...
- PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642
PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...
- PAT甲 1006. Sign In and Sign Out (25) 2016-09-09 22:55 43人阅读 评论(0) 收藏
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- pat 1006 Sign In and Sign Out(25 分)
1006 Sign In and Sign Out(25 分) At the beginning of every day, the first person who signs in the com ...
- PAT Sign In and Sign Out[非常简单]
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- 1006 Sign In and Sign Out (25 分)
1006 Sign In and Sign Out (25 分) At the beginning of every day, the first person who signs in the co ...
- 1006 Sign In and Sign Out (25)(25 分)思路:普通的时间比较题。。。
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
随机推荐
- JavaScript实现快速排序(Quicksort)
目前,最常见的排序算法大概有七八种,其中"快速排序"(Quicksort)使用得最广泛,速度也较快.它是图灵奖得主 东尼·霍尔(C. A. R. Hoare)于1960时提出来的. ...
- 【nginx下对服务器脚本php的支持】
安装php7 下载地址:https://secure.php.net/downloads.php这里下载的是:wget http://ar2.php.net/distributions/php ...
- 【ospf-vlink虚拟连接】
根据项目需求,搭建好如下拓扑图 配置rt1的环回 口地址及g0/0/0的ip地址 配置rt1的ospf 配置rt2的环回口地址和g0/0/1及g0/0/0的ip地址 \ 配置rt2的ospf 同理,配 ...
- nginx2goaccess.sh脚本内容
脚本github地址:https://github.com/stockrt/nginx2goaccess/blob/master/nginx2goaccess.sh 脚本内容: #!/bin/bash ...
- STM32进阶之串口环形缓冲区实现(转载)
转载自微信公众号“玩转单片机”,感谢原作者“杰杰”. 队列的概念 在此之前,我们来回顾一下队列的基本概念:队列 (Queue):是一种先进先出(First In First Out ,简称 FIFO) ...
- 【Leetcode】647. Palindromic Substrings
Description Given a string, your task is to count how many palindromic substrings in this string. Th ...
- 网站的robots.txt文件
什么是robots.txt? robots.txt是一个纯文本文件,是爬虫抓取网站的时候要查看的第一个文件,一般位于网站的根目录下.robots.txt文件定义了爬虫在爬取该网站时存在的限制,哪些部分 ...
- MyEclipse - 问题集 - Java compiler level does not match the version of the installed Java project facet
右键项目“Properties”,在弹出的“Properties”窗口左侧,单击“Project Facets”,打开“Project Facets”页面. 在页面中的“Java”下拉列表中,选择相应 ...
- iOS-合成图片(长图)
合成图片 直接合成图片还是比较简单的,现在的难点是要把,通过文本输入的一些基本数据也合成到一张图片中,如果有多长图片就合成长图. 现在的实现方法是,把所有的文本消息格式化,然后绘制到一个UILable ...
- linux开发基本库
1.ZeroMQ zmq是一个消息队列.可以在进程内.进程间.TCP.多播中,以消息为单位传输数据,而不是socket的字节流.官方主页上有下载.使用.文档,蛮全的. 常用模式有:Request-Re ...