用scanf"%d:%d:%d"里的冒号把时间转换成整数直接比较大小
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
struct f{
string ID;
int time1, time2;
}mem[10010];
bool cmp1(f f1, f f2) {
return f1.time1 < f2.time1 ;
}
bool cmp2(f f1, f f2) {
return f1.time2 > f2.time2;
}
int main() {
int n,a,b,c;
string s;
cin >> n;
for (int i = 0;i < n;i++) {
cin >> s;
scanf("%d:%d:%d", &a, &b, &c);
mem[i].ID = s;
mem[i].time1 = a * 10000 + b * 100 + c;
scanf("%d:%d:%d", &a, &b, &c);
mem[i].time2 = a * 10000 + b * 100 + c;
}
sort(mem, mem + n,cmp1);
cout << mem[0].ID << " " ;
sort(mem, mem + n, cmp2);
cout << mem[0].ID;
return 0;
}