链接:http://acm.hdu.edu.cn/showproblem.php?pid=1234
直接用strcmp()比较时间即可
#include <stdio.h> #include <string.h> int main() { bool judge(char t1[],char t2[]); char id[20]; char t1[20]; char t2[20]; char ans1[20]; char ans2[20]; char time1[20]; char time2[20]; int n; int m; scanf("%d",&n); while(n--) { memset(time1,' ',sizeof(time1)); memset(time2,' ',sizeof(time2)); scanf("%d",&m); while(m--) { scanf("%s%s%s",id,t1,t2); if(judge(t1,time1)) { strcpy(time1,t1); strcpy(ans1,id); } if(judge(time2,t2)) { strcpy(time2,t2); strcpy(ans2,id); } } printf("%s %s ",ans1,ans2); } return 0; } bool judge(char t1[],char t2[]) //判断t1是否早于t2 { int len1=strlen(t1); int len2=strlen(t2); if(len1==0||len2==0) return true; if(strcmp(t1,t2)<0) return true; else return false; }