compare函数写的不错
#pragma warning(disable:4996)
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
struct info {
char id[20];
int hh, mm, ss;
}temp,ans1,ans2;
bool compare(info p1, info p2)
{
if (p1.hh != p2.hh)
return p1.hh > p2.hh;
if (p1.mm != p2.mm)
return p1.mm > p2.mm;
return p1.ss > p2.ss;
}
int main()
{
int n;
scanf("%d", &n);
ans1.hh = 24, ans1.mm = 60, ans1.ss = 60;
ans2.hh = 0, ans2.mm = 0, ans2.ss = 0;
for (int i = 0; i < n; i++)
{
scanf("%s %d:%d:%d ",temp.id, &temp.hh, &temp.mm, &temp.ss);
if (compare(temp, ans1) == false)
ans1 = temp;
scanf("%d:%d:%d", &temp.hh, &temp.mm, &temp.ss);
if (compare(temp, ans2) == true)
ans2 = temp;
}
printf("%s %s",ans1.id,ans2.id);
return 0;
}