F - Middle of the Contest
Polycarp is going to participate in the contest. It starts at h1:m1 and ends at h2:m2. It is guaranteed that the contest lasts an even number of minutes (i.e. m1%2=m2%2, where x%y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Input
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
The first line of the input contains two integers h1 and m1 in the format hh:mm.
The second line of the input contains two integers h2 and m2 in the same format (hh:mm).
It is guaranteed that 0≤h1,h2≤23 and 0≤m1,m2≤59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m1%2=m2%2, where x%y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h3 and m3 (0≤h3≤23,0≤m3≤59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ‘:’.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
这就是求时间的中值,我的思路是吧小时换算成分钟求分钟的中值,最后转换成小时就可以了。
下面是我的代码。
// An highlighted block
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x1,x2,x3,y1,y2,y3;
scanf("%d:%d",&x1,&y1);
scanf("%d:%d",&x2,&y2);
x3=(((x1*60+y1)+(x2*60+y2))/2)/60;
y3=(((x1*60+y1)+(x2*60+y2))/2)%60;
if(x3>=10)
{
if(y3>=10)
printf("%d:%d\n",x3,y3);
else
printf("%d:0%d\n",x3,y3);
}
else
{
if(y3>=10)
printf("0%d:%d\n",x3,y3);
else
printf("0%d:0%d\n",x3,y3);
}
return 0;
}
若有错误或更好的建议欢迎留言,这是对我的帮助,谢谢!