Sign In and Sign Out
来源:互联网 发布:java ssh 编辑:程序博客网 时间:2024/06/17 02:49
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
下面是题解:
static String []name; static String []in; static String []out; static int min=0; static int max=0; public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=Integer.parseInt(scan.nextLine()); name=new String [n]; in=new String [n]; out=new String [n]; for(int i=0;i<n;i++) { String []s=scan.nextLine().split(" "); name[i]=s[0]; in[i]=s[1]; out[i]=s[2]; } scan.close(); for(int i=1;i<n;i++) { bijiao(i); } System.out.println(name[min]+" "+name[max]); } static void bijiao(int index) { String []s1=in[min].split(":"); String []s2=in[index].split(":"); if(Integer.parseInt(s1[0])>Integer.parseInt(s2[0])) { min=index; }else if(Integer.parseInt(s1[0])==Integer.parseInt(s2[0])) { if(Integer.parseInt(s1[1])>Integer.parseInt(s2[1])) { min=index; }else if(Integer.parseInt(s1[1])==Integer.parseInt(s2[1])) { if(Integer.parseInt(s1[2])>Integer.parseInt(s2[2])) { min=index; } } } s1=out[max].split(":"); s2=out[index].split(":"); if(Integer.parseInt(s1[0])<Integer.parseInt(s2[0])) { max=index; }else if(Integer.parseInt(s1[0])==Integer.parseInt(s2[0])) { if(Integer.parseInt(s1[1])<Integer.parseInt(s2[1])) { max=index; }else if(Integer.parseInt(s1[1])==Integer.parseInt(s2[1])) { if(Integer.parseInt(s1[2])<Integer.parseInt(s2[2])) { max=index; } } } }
- Sign In and Sign Out
- Sign In and Sign Out
- Sign In and Sign Out
- Sign In and Sign Out
- pat1006 Sign In and Sign Out
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out
- PAT1006. Sign In and Sign Out
- PAT1006. Sign In and Sign Out (25)
- PAT_1006: Sign In and Sign Out
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006 Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out
- PAT 1006. Sign In and Sign Out
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 垃圾收集器与内存分配策略
- 零散的小知识
- 中文、字母、数字自动换行
- 3个月没有写文章的一段自我总结
- Activity的四种启动模式
- Sign In and Sign Out
- [TravelNotes] CTSC 2017 & APIO 2017 & THUPC 2017 游记
- 让织梦的搜索页面支持dede标签的方法
- 复杂jstl取值的方式
- VBS实现发送邮件
- 梯度和Sobel导数
- grunt构建&文件合并&压缩
- 【插件动态加载方案】
- Linux 1