题目

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

题目解析

早上来的最早的人要开门,晚上离开的最晚的人要锁门。

给出M个人的编号 到达时间 离开时间

输出 开门的那个人的编号 锁门的那个人的编号

这题真没啥意思,不就是一个排序或者说比大小

千万不要去创建结构体,真没必要,我们只需要编号,所以直接用两个变量保存负责开门的编号,负责关门的编号,在读入这些人信息的时候直接做比较,根据到达时间判断改变这个两个变量就可以了。

至于怎么保存“时间”以及比较,你可以把它转为以00:00:00开始的秒数,但我比较懒,直接用string类对象比较,> < 就可以搞定,只是比较字符串可能比比较整数速度慢,但是影响不大。

代码

#include <iostream>
#include <string>
using namespace std; int main() { // m个员工
int m;
cin >> m;
// 开锁的员工,上锁的员工
string unlock_no, lock_no;
// 初始化开锁时间,上锁时间
string unlock_time = "23:59:59", lock_time = "00:00:00";
// 当前员工编号,到达时间,离开时间
string emp_no, sign_in_time, sign_out_time;
for (int i = 0; i < m; ++i) {
cin >> emp_no >> sign_in_time >> sign_out_time;
// 最早来的那个人开锁,通过string类对象比较方法
if (sign_in_time < unlock_time) {
unlock_time = sign_in_time;
unlock_no = emp_no;
}
// 最晚走的那个人锁门
if (sign_out_time > lock_time) {
lock_time = sign_out_time;
lock_no = emp_no;
}
}
// 开锁的 锁门的
cout << unlock_no << " " << lock_no;
return 0;
} // 将时间转为秒进行比较
// int main() {
// int n, minn = INT_MAX, maxn = INT_MIN;
// scanf("%d", &n);
// string unlocked, locked;
// for(int i = 0; i < n; i++) {
// string t;
// cin >> t;
// int h1, m1, s1, h2, m2, s2;
// scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
// int tempIn = h1 * 3600 + m1 * 60 + s1;
// int tempOut = h2 * 3600 + m2 * 60 + s2;
// if (tempIn < minn) {
// minn = tempIn;
// unlocked = t;
// }
// if (tempOut > maxn) {
// maxn = tempOut;
// locked = t;
// }
// }
// cout << unlocked << " " << locked;
// return 0;
// }

PAT 1006 Sign In and Sign Out (25分) 字符串比较的更多相关文章

  1. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  2. PAT甲级:1089 Insert or Merge (25分)

    PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...

  3. PAT 乙级 1080 MOOC期终成绩 (25 分)

    1080 MOOC期终成绩 (25 分) 对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的 ...

  4. pat 1002 A+B for Polynomials (25 分)

    1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...

  5. PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)

    1145 Hashing - Average Search Time (25 分)   The task of this problem is simple: insert a sequence of ...

  6. PAT 甲级 1066 Root of AVL Tree (25 分)(快速掌握平衡二叉树的旋转,内含代码和注解)***

    1066 Root of AVL Tree (25 分)   An AVL tree is a self-balancing binary search tree. In an AVL tree, t ...

  7. PAT 甲级 1055 The World's Richest (25 分)(简单题,要用printf和scanf,否则超时,string 的输入输出要注意)

    1055 The World's Richest (25 分)   Forbes magazine publishes every year its list of billionaires base ...

  8. PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)

    1047 Student List for Course (25 分)   Zhejiang University has 40,000 students and provides 2,500 cou ...

  9. PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*

    1039 Course List for Student (25 分)   Zhejiang University has 40000 students and provides 2500 cours ...

  10. shell练习--PAT试题1010:一元多项式求导 (25 分)(失败案例喜加一)

    ---恢复内容开始--- 1010 一元多项式求导 (25 分) 设计函数求一元多项式的导数.(注:x​n​​(n为整数)的一阶导数为nx​n−1​​.) 输入格式: 以指数递降方式输入多项式非零项系 ...

随机推荐

  1. 关于json转义中文

    服务器传递或者程序传递中,不识别读取到的JSON数据中 \u开头的数据. PHP 生成JSON的时候,必须将汉字不转义为 \u开头的UNICODE数据. 网上很多,但是其实都是错误的,正确的方法是在j ...

  2. 一张图记住Linux系统常用诊断工具

  3. C# 基础知识系列-13 常见类库(三)

    0. 前言 在<C# 基础知识系列- 13 常见类库(二)>中,我们介绍了一下DateTime和TimeSpan这两个结构体的内容,也就是C#中日期时间的简单操作.本篇将介绍Guid和Nu ...

  4. search(8)- elastic4s-search-query模式

    上篇提过query模式除对记录的筛选之外还对符合条件的记录进行了评分,即与条件的相似匹配程度.我们把评分放在后面的博文中讨论,这篇我们只介绍query查询. 查询可以分为绝对值查询和全文查询:绝对值查 ...

  5. JavaScript之浅谈内存空间

    JavaScript之浅谈内存空间 JavaScipt 内存自动回收机制 在JavaScript中,最独特的一个特点就是拥有自动的垃圾回收机制(周期性执行),这也就意味者,前端开发人员能够专注于业余, ...

  6. wx.request出现400 bad request的问题

    wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' , y: '' }, header: { 'content-type': 'a ...

  7. Inno Setup [Run] Section 双引号嵌套

    https://stackoverflow.com/questions/26257808/inno-setup-how-to-run-a-code-procedure-in-run-section-o ...

  8. Visual Studio 2015 + Windows 2012 R2, c++/cli Array::Sort() 抛出异常

    在Windows7上编译就是正常. 可见Windows2012 R2缺少了一些东西. 另外,有一个现象一样,但原因不一样的 https://stackoverflow.com/questions/46 ...

  9. 新版gitbook导出pdf

    文章目录 gitbook自带的npm模块gitbook 使用vscode的插件Markdown PDF 使用CommandBox GitBook Exporter 最近想把自己写的一个gitbook转 ...

  10. 【三剑客】sed命令

    1. Sed 简介 sed 是Stream Editor(流编辑器)的缩写,是操作.过滤和转换文本内容的强大工具.常用功能有增删改查,过滤,取行.   sed 是一种新型的,非交互式的编辑器. 它能执 ...