1006. Sign In and Sign Out (25)
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

题目大意:给出n个人的id、sign in时间、sign out时间,求最早进来的人和最早出去的人的ID~

PS:感谢github用户@fs19910227提供的pull request~

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;public class Main {static class Record {static DateFormat format = new SimpleDateFormat("HH:mm:ss");String id;Date start;Date end;Record(String id, String start, String end) throws ParseException {this.id = id;this.start = format.parse(start);this.end = format.parse(end);}}public static void main(String[] args) throws Exception {BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));int record_counts = Integer.valueOf(reader.readLine());String[] split = reader.readLine().split(" ");Record record = new Record(split[0], split[1], split[2]);Record earliest = record, latest = record;for (int i = 1; i < record_counts; i++) {split = reader.readLine().split(" ");Record newRecord = new Record(split[0], split[1], split[2]);if (newRecord.start.compareTo(earliest.start) < 0) {earliest = newRecord;}if (newRecord.end.compareTo(latest.end) > 0) {latest = newRecord;}}System.out.println(earliest.id + " " + latest.id);}
}

[Java] 1006. Sign In and Sign Out (25)-PAT甲级相关推荐

  1. 1006. Sign In and Sign Out (25)-PAT甲级真题

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  2. [Java] 1010. Radix (25)-PAT甲级

    1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...

  3. 1020. Tree Traversals (25) PAT甲级真题

    之前我看了这道题,实在是看不懂网上的解题答案,他们的具体思路基本上就是通过后续遍历和中序遍历,直接推出层次遍历. 我苦思冥想了半天,是在没看懂这种思路,于是想了一个笨点的但是也比较好理解的思路,通过后 ...

  4. 1078. Hashing (25)-PAT甲级真题

    1078. Hashing (25) The task of this problem is simple: insert a sequence of distinct positive intege ...

  5. 2020/7/25 pat甲级45分总结

    额,第一次考甲级,慌慌的,第一题第三题都比较简单,就都写得很快,然后第二题就死磕了..题目中的difference一直当成"差异"来理解,然后一直想不出测试用例的答案是咋的出来的. ...

  6. 哈密顿回路 Java题解 (图,模拟)【PAT甲级1122】

    输入样例: 6 10 6 2 3 4 1 5 2 5 3 1 4 1 1 6 6 3 1 2 4 5 6 7 5 1 4 3 6 2 5 6 5 1 4 3 6 2 9 6 2 1 6 3 4 5 2 ...

  7. 1121. Damn Single (25)-PAT甲级真题

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  8. 1090. Highest Price in Supply Chain (25)-PAT甲级真题

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. 1106. Lowest Price in Supply Chain (25)-PAT甲级真题(dfs,bfs,树的遍历)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

最新文章

  1. vscode 终端 进入node_安装了Node.js 从VScode 使用node -v 和 npm -v等命令却无效
  2. 问题1:U盘可以识别但无法打开;问题2:U盘成为启动盘之后如何恢复成普通U盘。
  3. UE4中的主要材料和光线跟踪
  4. MPLS服务合同到期了,是否该续签?
  5. kafka消费者开发方式小结
  6. FlyCms 是一个类似知乎以问答为基础的完全开源的JAVA语言开发的社交网络建站程序
  7. linux下最好的ftp服务器,用Linux系统构建高效FTP服务器
  8. 卸载VS2005不完全出现的安装问题
  9. NUC1419 位操作【位运算+STL】
  10. python3模拟扑克牌
  11. 创建一个WPF+EF应用程序
  12. upc 兔子与兔子(字符串Hash)
  13. 把电脑做成服务器系统,把电脑做成云盘服务器
  14. 我的2019全年目标
  15. marshmallow——Nested 类型
  16. 微积分精简版复习提纲
  17. C++之char , signed char , unsigned char(转)
  18. head/tail/tail -f
  19. 微软外包人才之道:一流外包团队如何打造
  20. STM32F103—有关BH1750(GY-302)环境光强度传感器模块的代码

热门文章

  1. 排列算法 C++实现
  2. theme为dialog的Activity如何充满全屏
  3. Oracle 禁止操作系统认证登录
  4. react-navigation使用介绍及UI组件外实现统一跳转
  5. 23.3. 操作系统监控需求
  6. shell 脚本基础
  7. 修复群集无法切换磁盘问题
  8. Word 2010、Excel 2010中插入日期与时间(转)
  9. [CareerCup][Google Interview] Find kth number in a BST
  10. 系统集成资质培训 - 论文:论项目的人力资源管理