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,表示共有 M 个人的签到签出记录。
接下来 M 行,每行的形式如下:
ID_number Sign_in_time Sign_out_time
时间以 HH:MM:SS 形式给出,ID_number 是一个长度不超过 15 的字符串。
输出格式
共一行,输出开门人和锁门人的ID_number,用一个空格隔开。
思路:
将签到时间、签离时间都转换为距离00:00:00
的秒数,可以方便找出最大最小
用map<string,pair<int,int>> 将ID与对应的时间联系在一起
C++:
#include<bits/stdc++.h>
using namespace std;
const int N=15;
string s[N];
map<string,pair<int,int> > mp;
int main(){
int n,i=0;
cin>>n;
int m=n;
while(n--){
cin>>s[i];
int h1,m1,s1,h2,m2,s2;
scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
int date1=(m1*60+s1+h1*3600),date2=(m2*60+s2+h2*3600);
mp[s[i]]={date1,date2};
i++;
}
int min=24*3600,max = 0;
string s_min="",s_max="";
for(int j = 0;j<m;j++){
if(mp[s[j]].first<min) {
min = mp[s[j]].first;
s_min=s[j];
}
if(mp[s[j]].second>max){
max = mp[s[j]].second;
s_max = s[j];
}
}
cout<<s_min<<" "<<s_max;
return 0;
}