时间比较 可以hour10000+minute100+second来比较,比分开比较快的多
每次输入直接和最大和最小值比较,然后替换
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int M = 0;
int h1,m1,s1;
int h2,m2,s2;
int time1;
int time2;
int min = 999999;
int max = -1;
char fir[15],las[15],id[15];
scanf("%d",&M);
int i = 0;
for(i = 0 ;i<M;i++)
{
scanf("%s %d:%d:%d %d:%d:%d",id,&h1,&m1,&s1,&h2,&m2,&s2);
time1 = h1*10000+m1*100+s1;
if(min>time1)
{
min = time1;
strcpy(fir,id);
}
time2 = h2*10000+m2*100+s2;
if(max<time2)
{
max = time2;
strcpy(las,id);
}
}
printf("%s %s",fir,las);
}
在这里插入代码片