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 ...
随机推荐
- 牛B的swift屏幕旋转经验终结者(OC统一思路)
牛B的swift屏幕旋转经验终结者(OC统一思路) 1.AppDelegate (1)定义变量 var blockRotation: Bool = false (2)定义方法 Swift代码 func ...
- HTML基础之标签简单认识
简介 HTML(Hyper Text Markup Language)译为"超文本标记语言",主要是通过HTML标记对网页中的文本.图片.声音等内容进行描述 HTML之所以称为超文 ...
- 简明 ES6 模块
简明 ES6 模块 1.什么是模块 模块就是一段代码,这段代码可以反复使用,经常单独写成一个文件,一旦加载会立即执行. 2.导出 导出有 2 种方式:命名导出和默认导出,分别用关键字export和ex ...
- CommonJs模块规范
1.什么是模块化 文件作用域 通信规则 加载 require 导出 exports 2.CommonJs模块规范 在Node中的Javascript还有一个很重要的概念:模块概念 模块作用域 使用re ...
- #leetcode刷题之路9- 回文数
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1:输入: 121输出: true 示例 2:输入: -121输出: false解释: 从左向右读, 为 ...
- 利用python实现《数据挖掘——概念与技术》一书中描述的Apriori算法
from itertools import combinations data = [['I1', 'I2', 'I5'], ['I2', 'I4'], ['I2', 'I3'], ['I1', 'I ...
- PHP(YII2实现) 微信网页授权
参考地址 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842 实现步骤分析: 获取code->access ...
- Hadoop(15)-MapReduce框架原理-FileInputFormat的实现类
1. TextInputFormat 2.KeyValueTextInputFormat 3. NLineInputFormat
- Java学习笔记八:Java的流程控制语句之循环语句
Java的流程控制语句之循环语句 一:Java循环语句之while: 生活中,有些时候为了完成任务,需要重复的进行某些动作.如参加 10000 米长跑,需要绕 400 米的赛道反复的跑 25 圈.在 ...
- Leecode刷题之旅-C语言/python-88合并两个有序数组
/* * @lc app=leetcode.cn id=88 lang=c * * [88] 合并两个有序数组 * * https://leetcode-cn.com/problems/merge-s ...