[恢]hdu 1234

2011-12-19 17:24:45

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1234

题意:每天有n个人签到和离开,问最早到的和最后离开的人的名字。水。

代码:

# include <stdio.h>
# include <string.h>


typedef struct tm{
int h, m, s ;
}tm ;


int isless(tm t1, tm t2)
{
if (t1.h != t2.h) return t1.h < t2.h ;
if (t1.m != t2.m) return t1.m < t2.m ;
return t1.s < t2.s ;
}


int ismore (tm t1, tm t2)
{
if (t1.h != t2.h) return t1.h > t2.h ;
if (t1.m != t2.m) return t1.m > t2.m ;
return t1.s > t2.s ;
}


int main ()
{
int T, n, i ;
char s1[20], s2[20], name[20] ;
tm t1, t2, ts, te ;
scanf ("%d%*c", &T) ;
while (T--)
{
scanf ("%d%*c", &n) ;
scanf ("%s %d:%d:%d %d:%d:%d%*c",
s1, &ts.h, &ts.m, &ts.s, &te.h, &te.m, &te.s) ;
strcpy (s2, s1) ;

for (i = 1 ; i < n ; i++)
{
scanf ("%s %d:%d:%d %d:%d:%d%*c", name,
&t1.h, &t1.m, &t1.s, &t2.h, &t2.m, &t2.s) ;
if (isless(t1, ts))
{
ts = t1 ;
strcpy (s1, name) ;
}
if (ismore(t2, te))
{
te = t2 ;
strcpy (s2, name) ;
}
}
printf ("%s %s\n", s1, s2) ;
}
return 0 ;
}



原文地址:https://www.cnblogs.com/lzsz1212/p/2315234.html