#include<stdio.h> #include<string.h> #include<stdlib.h> int N; typedef struct node { char name[20]; int start; int end; }node; node a[87000]; int comp1(const void *a,const void *b) { return ((node*)a)->start-((node*)b)->start;//从小到大排序 } int comp2(const void *a,const void *b) { return ((node*)a)->end-((node*)b)->end; } int main(int argc, char *argv[]) { freopen("1013.in","r",stdin); scanf("%d",&N); char s[20]; char e[20]; int i; int sh,sm,ss; int eh,em,es; while(N--) { int num; memset(a,0,sizeof(a)); scanf("%d",&num); for(i=0;i<num;++i) { scanf("%s",a[i].name); scanf("%d:%d:%d %d:%d:%d",&sh,&sm,&ss,&eh,&em,&es); a[i].start=sh*3600+sm*60+ss; a[i].end=eh*3600+em*60+es; } qsort(a,num,sizeof(node),comp1); strcpy(s,a[0].name); qsort(a,num,sizeof(node),comp2); strcpy(e,a[num-1].name); printf("%s %s\n",s,e); } return 0; }
原文地址:http://blog.csdn.net/wdkirchhoff/article/details/41911759