cpp
#include <bits/stdc++.h>
using namespace std;
int change(const string& ss) {
int sum = 0;
for(char c : ss) {
int n = c - '0';
sum = sum * 10 + n;
}
return sum;
}
int main() {
int n;
cin >> n;
vector<string> name(n);
int l_index = 0;
int l = 99999999;
int h_index = 0;
int h = -1;
for(int i = 0; i < n; i++) {
string name1;
cin >> name1;
name[i] = name1;
string time1, time2;
cin >> time1 >> time2;
int r1 = change(time1.substr(0, 2));
int r2 = change(time1.substr(3, 2));
int r3 = change(time1.substr(6, 2));
int now_sum1 = r1 * 3600 + r2 * 60 + r3;
if (now_sum1 < l) {
l_index = i;
l = now_sum1;
}
r1 = change(time2.substr(0, 2));
r2 = change(time2.substr(3, 2));
r3 = change(time2.substr(6, 2));
int now_sum2 = r1 * 3600 + r2 * 60 + r3;
if (now_sum2 > h) {
h_index = i;
h = now_sum2;
}
}
cout << name[l_index] << " " << name[h_index] << endl;
return 0;
}
字符串转数字、字符串取子串