水一篇题解,每次计算来去航班的时间差(秒制),将得到的时间差进行对半除即可得到一次航行所花时间。然后依次 /3600 得到hour, %3600/60 得到min, %3600%60 得到sec。需要注意的是这里的输入可以借助printf的固定格式输入,非常的方便,还要就是对tmep的处理,如果输入没有带(+num)也没关系,就是temp为0即可,最后还需要处理的就是第一次有(+num), 第二次没有(+num),这个一定要重新重置一下temp = 0 否则会出现有12个小时的额外时间或在答案的基础上减少12个小时
include[HTML_REMOVED]
using namespace std;
//const int N = 1e3+5;
// int hour,min,sec;
// scanf(“%d:%d:%d”,&hour,&min,&sec);
// cout<[HTML_REMOVED]>t;
while(t–){
int time = 0;
int temp = 0;
scanf(“%d:%d:%d %d:%d:%d (+%d)”,&h[0],&m[0],&s[0],&h[1],&m[1],&s[1],&temp);
time+=(h[1]-h[0])3600+(m[1]-m[0])60+(s[1]-s[0])+temp243600;
temp = 0;
scanf(“%d:%d:%d %d:%d:%d (+%d)”,&h[0],&m[0],&s[0],&h[1],&m[1],&s[1],&temp);
time+=(h[1]-h[0])3600+(m[1]-m[0])60+(s[1]-s[0])+temp243600;
time/=2;
printf(“%02d:%02d:%02d\n”,time/3600,time%3600/60,time%3600%60);
}
return 0;
}