题目链接
通过把时间转化成整形的数据来比较即:
15:30:28 ——>153028
方便操作且易于实现,再利用两个排序方法分别对到达离去时间排序得到结果;
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<stack>
#include<math.h>
#include<vector>
using namespace std;
struct peo {
string id;
int timee;
int timeo;
};
bool cmp1(peo a, peo b)//分别按到达时间和离去时间排序
{
return a.timee < b.timee;
}
bool cmp2(peo a, peo b)
{
return a.timeo < b.timeo;
}
int main() {
vector<peo> s;
int n;
cin >> n;
for (int i = 0;i < n;i++)
{
peo tmp;
cin >> tmp.id;
int x, y, z;
scanf("%d:%d:%d", &x, &y, &z);
tmp.timee = x * 10000 + y * 100 + z;
scanf("%d:%d:%d", &x, &y, &z);
tmp.timeo = x * 10000 + y * 100 + z;
s.push_back(tmp);
}
sort(s.begin(), s.end(), cmp1);
cout << s[0].id << " ";
sort(s.begin(), s.end(), cmp2);
cout << s[n - 1].id;
return 0;
}