#include<iostream>
using namespace std;
struct node
{
char id[20];
int hh,mm,ss;
}temp,f,l;
bool panduan(node x,node y)
{
if (x.hh>y.hh) {return(true);}
else if ( x.hh==y.hh && x.mm>y.mm) {return(true);}
else if ( ( x.hh==y.hh) && (x.mm=y.mm) && (x.ss>y.ss) ){return(true);}
return false;
}
int main()
{
int n;
cin>>n;
f.hh=24;f.mm=60;f.ss=60;
l.hh=0; l.mm=0; l.ss=0;
for (int i=0;i<n;i++)
{
scanf("%s %d:%d:%d",&temp.id,&temp.hh,&temp.mm,&temp.ss);
if (panduan(f,temp)){f=temp;}
if (panduan(temp,l)){l=temp;}
scanf(" %d:%d:%d",&temp.hh,&temp.mm,&temp.ss);
if (panduan(f,temp)){f=temp;}
if (panduan(temp,l)){l=temp;}
}
cout<<f.id<<" "<<l.id;
system("pause");
return 0;
using namespace std;
struct node
{
char id[20];
int hh,mm,ss;
}temp,f,l;
bool panduan(node x,node y)
{
if (x.hh>y.hh) {return(true);}
else if ( x.hh==y.hh && x.mm>y.mm) {return(true);}
else if ( ( x.hh==y.hh) && (x.mm=y.mm) && (x.ss>y.ss) ){return(true);}
return false;
}
int main()
{
int n;
cin>>n;
f.hh=24;f.mm=60;f.ss=60;
l.hh=0; l.mm=0; l.ss=0;
for (int i=0;i<n;i++)
{
scanf("%s %d:%d:%d",&temp.id,&temp.hh,&temp.mm,&temp.ss);
if (panduan(f,temp)){f=temp;}
if (panduan(temp,l)){l=temp;}
scanf(" %d:%d:%d",&temp.hh,&temp.mm,&temp.ss);
if (panduan(f,temp)){f=temp;}
if (panduan(temp,l)){l=temp;}
}
cout<<f.id<<" "<<l.id;
system("pause");
return 0;
}
1.设置结构体让处理更方便
2.c形式对格式化输入极度友好
格式
scanf("%s %d:%d:%d",&temp.id,&temp.hh,&temp.mm,&temp.ss);
注意%和&