time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp is going to participate in the contest. It starts at
h
1
:
m
1
h1:m1
and ends at
h
2
:
m
2
h2:m2
. It is guaranteed that the contest lasts an even number of minutes (i.e.
m
1
%2=
m
2
%2
m1%2=m2%2
, where
x%y
x%y
is
x
x
modulo
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
to
11:00
11:00
then the answer is
10:30
10:30
, if the contest lasts from
11:10
11:10
to
11:12
11:12
then the answer is
11:11
11:11
.
Input
The first line of the input contains two integers
h
1
h1
and
m
1
m1
in the format hh:mm.
The second line of the input contains two integers
h
2
h2
and
m
2
m2
in the same format (hh:mm).
It is guaranteed that
0≤
h
1
,
h
2
≤23
0≤h1,h2≤23
and
0≤
m
1
,
m
2
≤59
0≤m1,m2≤59
.
It is guaranteed that the contest lasts an even number of minutes (i.e.
m
1
%2=
m
2
%2
m1%2=m2%2
, where
x%y
x%y
is
x
x
modulo
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
h3
and
m
3
m3
(
0≤
h
3
≤23,0≤
m
3
≤59
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
Copy
10:00
11:00
Output
Copy
10:30
Input
Copy
11:10
11:12
Output
Copy
11:11
Input
Copy
01:02
03:02
Output
Copy
02:02
题解:给你两个时间,这两个时间都是在同一天内的,求出两个时间的中间时刻.
这个好像没啥好说的,就是先算分钟部分,看看能不能进位;时钟部分相除后有没有多余.输出的时候要注意点.
#include <bits/stdc++.h>
int main(){
int h1,m1,h2,m2;
scanf("%d:%d%d:%d",&h1,&m1,&h2,&m2);
h1+=h2;
m1+=m2;
if(m1>=60) h1+=m1/60,m1%=60;
if(h1%2==1) m1+=60;
h1/=2;
m1/=2;
if(h1<=9) printf("0%d:",h1); else printf("%d:",h1);
if(m1<=9) printf("0%d
",m1); else printf("%d
",m1);
//printf("%d:%d
",h1,m1);
return 0;
}
看了官方的题解;
#include <bits/stdc++.h>
using namespace std;
int main()
{
int h1,m1,h2,m2;
scanf("%d:%d%d:%d",&h1,&m1,&h2,&m2);
int t1=h1*60+m1,t2=h2*60+m2;
t1=(t1+t2)/2;
printf("%02d:%02d
",t1/60,t1%60);
//cout << "Hello world!" << endl;
return 0;
}
原来输出可以这样的啊(滑稽),真好用.
算法也很清晰,完美.