Polycarp is going to participate in the contest. It starts at h 1 : m 1 h1:m1 h1:m1 and ends at h 2 : m 2 h2:m2 h2:m2. It is guaranteed that the contest lasts an even number of minutes (i.e. m 1 m_1 m1% 2 2 2= m 2 m_2 m2% 2 2 2, where x x x% y y y is x x x modulo y y 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.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10 : 00 10:00 10:00 to 11 : 00 11:00 11:00 then the answer is 10 : 30 10:30 10:30, if the contest lasts from 11:10 to 11 : 12 11:12 11:12 then the answer is 11 : 11 11:11 11:11.
Input
The first line of the input contains two integers
h
1
h_1
h1 and
m
1
m_1
m1 in the format
h
h
:
m
m
hh:mm
hh:mm.
The second line of the input contains two integers h 2 h_2 h2 and m 2 m_2 m2 in the same format ( h h : m m ) (hh:mm) (hh:mm).
It is guaranteed that 0 ≤ \leq ≤ h 1 , h 2 h_1,h_2 h1,h2 ≤ \leq ≤ 23 and 0 ≤ \leq ≤ m 1 , m 2 m_1,m_2 m1,m2 ≤ \leq ≤ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m 1 m_1 m1% 2 2 2= m 2 m_2 m2% 2 2 2, where x x x% y y y is x x x modulo y y 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 h 3 h_3 h3 and m 3 m_3 m3 ( 0 0 0 ≤ \leq ≤ h 3 h_3 h3 ≤ \leq ≤ 23 23 23, 0 ≤ m 3 ≤ 59 0\leq m_3 \leq 59 0≤m3≤59) corresponding to the midpoint of the contest in the format h h : m m hh:mm 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 |
题目大意
求一天中任意两个时间的中间时间。
解题思路
因为两个时刻的分钟没有确定的相对大小,那么我就把两个时刻都转换为对应的分钟数,那么中间时刻就为初始时刻加上两个时刻分钟数之差的一半。然后再转换为对应的时刻即可。之前想的思路错误就在直接取余计算中间时刻的时间,忽视了分钟数还有可能对小时产生的进位。
AC代码
#include<bits/stdc++.h>
const int Max_N=1e3+6;
using namespace std;
int main()
{
int h1,h2,m1,m2;
char c;
cin>>h1>>c>>m1;
cin>>h2>>c>>m2;
int mid=(h2*60+m2)-(h1*60+m1);
mid/=2;
h2=(h1*60+m1+mid)/60;
m2=(h1*60+m1+mid)%60;
printf("%02d:%02d",h2,m2);
}
总结
这道题特别的简单,但为什么又要花时间来写这篇博客呢?因为这道题的做题经历特别有教育意义。因为自己思路上的大意,导致花了特别多的时间。