这道题没什么难度 水题
用map或者vector等容器来做速度很快
我这里用map, 把时间转换成数字,把数字用作map的key 然后维护这个key以从小到大 从大到小 两种方式排序
然后分别输出第一个值即可
#include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<string>
using namespace std;
int chartoint(string s) {
int a = (s[0] - '0') * 10;
int b = (s[1] - '0');
int shi = a + b;
int c = (s[3] - '0') * 10;
int d = (s[4] - '0');
int fen = c + d;
int e = (s[6] - '0') * 10;
int f = (s[7] - '0');
int miao = e + f;
return shi * 3600 + fen * 60 + miao;
}
map<string, int, less<int> > roin;
map<string, int, greater<int> > roout;
int n;
void solver() {
map<string, int> ::iterator it;
it = roin.begin();
cout << (it->first) << " ";
it = roout.begin();
cout << (it->first);
}
int main()
{
cin >> n;
string s, s1,s2;
int in, out;
for (int i = 0; i < n; i++) {
cin >> s >> s1 >> s2;
in = chartoint(s1);
out = chartoint(s2);
roin[s] = in;
roout[s] = out;
}
return 0;
}