1.没用脑子写的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
struct node
{
char num[20];
int h1,m1,s1;
int h2,m2,s2;
}a[100000];
int cmp1(node a,node b)
{
if(a.h1!=b.h1)
return a.h1<b.h1;
else if(a.m1!=b.m1)
return a.m1<b.m1;
else if(a.s1!=b.s1);
return a.s1<b.s1;
}
int cmp2(node a,node b)
{
if(a.h2!=b.h2)
return a.h2>b.h2;
else if(a.m2!=b.m2)
return a.m2>b.m2;
else if(a.s2!=b.s2);
return a.s2>b.s2;
}
int main()
{
int m,n;
scanf("%d",&n);
while(n--)
{
memset(a,0,sizeof(a));
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%s",a[i].num);
scanf("%d:%d:%d",&a[i].h1,&a[i].m1,&a[i].s1);
scanf("%d:%d:%d",&a[i].h2,&a[i].m2,&a[i].s2);
}
sort(a,a+m,cmp1);
printf("%s",a[0].num);
sort(a,a+m,cmp2);
printf(" %s\n",a[0].num);
}
return 0;
}
2.稍微用用脑子
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
struct node
{
char num[20];
int s;
int e;
}a[100000];
int cmp1(node a,node b)
{
return a.s<b.s;
}
int cmp2(node a,node b)
{
return a.e>b.e;
}
int main()
{
int m,n;
int hour,minute,second;
scanf("%d",&n);
while(n--)
{
memset(a,0,sizeof(a));
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%s",a[i].num);
scanf("%d:%d:%d",&hour,&minute,&second);
a[i].s=second+minute*60+hour*3600;
scanf("%d:%d:%d",&hour,&minute,&second);
a[i].e=second+minute*60+hour*3600;
}
sort(a,a+m,cmp1);
printf("%s",a[0].num);
sort(a,a+m,cmp2);
printf(" %s\n",a[0].num);
}
return 0;
}
3.还能简单点
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
struct node
{
string num , s , e;
} a[100000];
int cmp1(node a , node b)
{
return a.s < b.s;
}
int cmp2(node a , node b)
{
return a.e > b.e;
}
int main()
{
int n,m;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
for(int i = 0; i < m ; i ++)
cin >> a[i].num >> a[i].s >> a[i].e;
sort(a , a + m , cmp1);
cout<<a[0].num;
sort(a , a + m , cmp2);
cout<<" "<<a[0].num<<endl;
}
return 0;
}