开门人和关门人
原题链接:点击查看
每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请根据记录找出当天开门和关门的人。
Input
测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。
到、签离记录,请根据记录找出当天开门和关门的人。
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为
证件号码 签到时间 签离时间
其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
Output 对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,
且没有多人同时签到或者签离的情况。
Sample Input
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:40Sample Output
ME3021112225321 ME3021112225321 EE301218 MA301134 SC3021234 CS301133
感觉自己写的很麻烦,如果在录入时间的时候全部转化为以秒为单位的话,就用不到定义的compare函数了,直接比较大小就行了.
还有就是用了strcpy(string1,string2)进行字符串赋值.
AC代码:
#include<stdio.h>
#include<string.h>
int compare(int a,int b,int c,int x,int y,int z){
if(a>x)
return 1;
else if(a<x)
return 0;
else{
if(b>y)
return 1;
else if(b<y)
return 0;
else{
if(c>z)
return 1;
else
return 0;
}
}
}
int main(){
int n;
scanf("%d",&n);
while(n--){
int m;
scanf("%d",&m);
char begin[15];
char end[15];
char peo[15]; //第一个进入和最后一个离开及可能
int entry_time_result_h,entry_time_result_m,entry_time_result_s;
int end_time_result_h,end_time_result_m,end_time_result_s;
int entry_time_h,entry_time_m,entry_time_s;
int end_time_h,end_time_m,end_time_s;
scanf("%s",begin);
strcpy(end,begin);
scanf("%d:%d:%d",&entry_time_result_h,
&entry_time_result_m,&entry_time_result_s);
scanf("%d:%d:%d",&end_time_result_h,
&end_time_result_m,&end_time_result_s); //录入第一组数据
m -= 1;
while(m--){
scanf("%s",peo);
scanf("%d:%d:%d",&entry_time_h,&entry_time_m,&entry_time_s);
scanf("%d:%d:%d",&end_time_h,&end_time_m,&end_time_s);
if(compare(entry_time_result_h,entry_time_result_m,entry_time_result_s,
entry_time_h,entry_time_m,entry_time_s)){
entry_time_result_h = entry_time_h;
entry_time_result_m = entry_time_m;
entry_time_result_s = entry_time_s;
strcpy(begin,peo); //进入时间更新
}
if(!compare(end_time_result_h,end_time_result_m,end_time_result_s,
end_time_h,end_time_m,end_time_s)){
end_time_result_h = end_time_h;
end_time_result_m = end_time_m;
end_time_result_s = end_time_s;
strcpy(end,peo); //结束时间更新
}
}
printf("%s %s\n",begin,end);
}
return 0;
}