按照题意需要输出时间最早的字符串和最晚的字符串。
思路:将输入的时钟直接转换成秒数再比较大小,用T记录秒数,记录下最多的秒数和最少的秒数,用s数组记录此时的字符串。
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int MaxT=0, MinT=999999, num,T;
int a, b, c, d, e, f;
string t[10],s[2];
cin >> num;
for (int i = 0; i < num; i++) {
cin >> t[i];
scanf("%d:%d:%d %d:%d:%d", &a, &b, &c, &d, &e, &f);
T = a * 3600 + b * 60 + c;
if (T < MinT) {
MinT = T;
s[0] = t[i];
}
T = d * 3600 + e * 60 + c;
if (T > MaxT) {
MaxT = T;
s[1] = t[i];
}
}
cout << s[0] << " " << s[1];
}