PAT-PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25) (简单题)【一星级】
来源:互联网 发布:淘宝新店怎么做起来 编辑:程序博客网 时间:2024/05/10 00:40
题目链接:http://www.patest.cn/contests/pat-a-practise/1006
题面:
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:3CS301111 15:30:28 17:00:10SC3021234 08:00:00 11:25:25CS301133 21:45:00 21:58:40Sample Output:
SC3021234 CS301133
题目大意:
有很多条消息记录,问最早进来的那个人和最迟离开的那个人的ID是什么。
解题:
一开始想着先把时间转换为数值再比较,但字符串的字典序刚好满足时间先后关系,直接比较就行了。
代码:
#include <cstdio>#include <vector>#include <iostream>#include <string>#include <algorithm>using namespace std;struct record{string ID,signin_time,signout_time;};bool cmp1(record a,record b){return a.signin_time<b.signin_time;}bool cmp2(record a,record b){return a.signout_time>b.signout_time;}int main(){ vector <record> v;record tmp;int n;string a,b,c;cin>>n; for(int i=0;i<n;i++){cin>>a>>b>>c;tmp.ID=a;tmp.signin_time=b;tmp.signout_time=c;v.push_back(tmp);}sort(v.begin(),v.end(),cmp1);cout<<v[0].ID<<" ";sort(v.begin(),v.end(),cmp2);cout<<v[0].ID<<endl;return 0;}
- PAT-PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25) (简单题)【一星级】
- PAT (Advanced Level) Practise 1006 Sign In and Sign Out
- 1006. Sign In and Sign Out (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25)
- PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25)
- PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25)
- 【PAT Advanced Level】1006. Sign In and Sign Out (25)
- 【PAT (Advanced Level)】1006. Sign In and Sign Out (25)
- 【PAT】【Advanced Level】1006. Sign In and Sign Out (25)
- PAT (Advanced Level) Practise 1006Sign In and Sign Out (25)
- PAT(Advanced level) 1006. Sign In and Sign Out
- 浙大 PAT Advanced level 1006. Sign In and Sign Out
- PAT (Advanced) 1006. Sign In and Sign Out (25)
- Pat(Advanced Level)Practice--1006(Sign In and Sign Out)
- PAT Advanced Level 1006:Sign In and Sign Out
- PAT(Advanced Level) 1006 - Sign In and Sign Out(水题)
- 【c++】PAT (Advanced Level) 1006. Sign In and Sign Out (25)
- PAT (Advanced Level) 1006. Sign In and Sign Out (25) 字符串比较
- HDU 3336 Count the string(KMP+Next数组递推)
- 题目:翻转字符串
- scala学习第三章数组相关操作
- typedef 定义函数指针(匿名函数)
- MFC获取输入框的值
- PAT-PAT (Advanced Level) Practise 1006. Sign In and Sign Out (25) (简单题)【一星级】
- ZOJ 1610 Count the Colors(数组模拟)
- 最小生成树算法--Kruskal
- 题目:翻转链表
- bzoj 2818 Gcd(莫比乌斯+gcd(a,b)=d) 经典
- 数据持久化 (沙盒, 数据储存)
- 题目:落单的数
- 黑马程序员---学习笔记5:二维数组
- 详解。。设计思想与设计模型2--------beginer