Codeforces Round #544(Div. 3)--A Middle of the Contest(简单模拟题)

Middle of the Contest

time limit per test1 second
memory limit per test 256 megabytes

题目链接https://codeforces.com/contest/1133/problem/A

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.

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:12then the answer is 11:11.

Input
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


题意:给你开始时间和结束时间,请输出中间时间,输入保证在同一天。
emmm。。。一道比较简单的模拟题,将时间全部转化为分钟再转化回去,注意分钟不能超过60,还有位数不足时要补前导零。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int h1,h2,m1,m2;
	scanf ("%d:%d",&h1,&m1);
	scanf ("%d:%d",&h2,&m2);
	int time=(h2-h1)*60+m2-m1;     //中间的总用时
	time/=2;
	int h=time/60,m=time%60;
	if (m+m1>=60) h++,m-=60;
	if (h1+h<10) printf ("0%d:",h1+h);
	else printf ("%d:",h1+h);
	if (m1+m<10) printf ("0%d\n",m1+m);
	else printf ("%d\n",m1+m);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43906000/article/details/88358262