3 1 ME3021112225321 00:00:00 23:59:59 2 EE301218 08:05:35 20:56:35 MA301134 12:35:45 21:40:42 3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40
ME3021112225321 ME3021112225321 EE301218 MA301134 SC3021234 CS301133
当然这道题如果我们按照小时分钟秒排序,会很麻烦。所以我们可以把小时,分钟全部换算成秒来进行计算。
具体看代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
struct node
{
char str[20];
int star,end;
}c[1000];
bool cmp1(node x,node y)
{
return x.star<y.star;
}
bool cmp2(node x,node y)
{
return x.end>y.end;
}
int main()
{
int ncase,n;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int x1,x2,x3;
scanf("%s %d:%d:%d",c[i].str,&x1,&x2,&x3);
c[i].star=x3+x2*60+x1*3600;
scanf("%d:%d:%d",&x1,&x2,&x3);
c[i].end=x3+x2*60+x1*3600;
}
sort(c,c+n,cmp1);
printf("%s ",c[0].str);
sort(c,c+n,cmp2);
printf("%s\n",c[0].str);
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/su20145104009/article/details/47054219