#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stdio.h>
#include<iterator>
#include<algorithm>
/*
Problem Description
每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请根据记录找出当天开门和关门的人。
Input
测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为
证件号码 签到时间 签离时间
其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
Output
对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,
且没有多人同时签到或者签离的情况。
Sample Input
3 三天
1 第一天
ME3021112225321 00:00:00 23:59:59
2 第二天
EE301218 08:05:35 20:56:35
MA301134 12:35:45 21:40:42
3 第三天
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output
ME3021112225321 00:00:00
ME3021112225321 23:59:59
EE301218 08:05:35
MA301134 21:40:42
SC3021234 08:00:00
CS301133 21:58:40
*/
using namespace std;
class time
{
public:
time(string ml, string me, string mname):l(ml),e(me),name(mname)
{
}
string name;
string e;
string l;
};
bool cmp1(const time& a, const time& b)
{
return a.e < b.e;
}
bool cmp2(const time& a, const time& b)
{
return a.l >= b.l;
}
int main()
{
int n;
cin>>n;
while(n>0)
{
vector<time> v;
string first,last;
int m;
cin>>m;
while(m>0)
{
string s1,s2,s3;
cin>>s1>>s2>>s3;
time t( s3,s2,s1);
v.push_back(t);
m--;
}
//输出最早开门人
sort(v.begin(),v.end(),cmp1);
cout<<v[0].name<<" "<<v[0].e<<endl;
//输出最晚关门人
sort(v.begin(),v.end(),cmp2);
cout<<v[0].name<<" "<<v[0].l<<endl;
cout<<endl<<endl;
n--;
}
}
开门人和关门人
最新推荐文章于 2024-08-05 20:49:33 发布