Polycarp is going to participate in the contest. It starts at h1:m1h1:m1 and ends at h2:m2h2:m2. It is guaranteed that the contest lasts an even number of minutes (i.e. m1%2=m2%2m1%2=m2%2, where x%yx%y is xx modulo yy). 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:0010:00 to 11:0011:00 then the answer is 10:3010:30, if the contest lasts from 11:1011:10 to 11:1211:12 then the answer is 11:1111:11.
Input
The first line of the input contains two integers h1h1 and m1m1 in the format hh:mm.
The second line of the input contains two integers h2h2 and m2m2 in the same format (hh:mm).
It is guaranteed that 0≤h1,h2≤230≤h1,h2≤23 and 0≤m1,m2≤590≤m1,m2≤59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m1%2=m2%2m1%2=m2%2, where x%yx%y is xx modulo yy). 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 h3h3 and m3m3 (0≤h3≤23,0≤m3≤590≤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 ':'.
시간문제? 하도 풀어서 편하게 풀었다. 마! Polycarp! 초까지 들고온나!
아무튼,, 처음에는 h1 - h2한거를 뭉텅이로 만든 다음 2를 나누고 다시 h2에 더할 생각이었다. 그런데 적다보니 한 번에 식 세울 수 있어서 하나로 묶었다.
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
using i64 = long long;
int main() {
int h1, m1;
int h2, m2;
char tmp;
scanf("%d%c%d", &h1, &tmp, &m1);
scanf("%d%c%d", &h2, &tmp, &m2);
int sum = (h2*60 + m2 + h1*60 + m1)/2;
printf("%02d:%02d", sum/60, sum%60);
return 0;
}
코드도 별거 없다. 입력 받고 뭉텅이 만들어서 출력할 때는 나눠줬다.
int main()
{
int h1, m1, h2, m2;
scanf("%d:%d", &h1, &m1);
scanf("%d:%d", &h2, &m2);
int t = ((h1 + h2) * 60 + m1 + m2) / 2;
printf("%02d:%02d\n", t / 60, t % 60);
return 0;
}
엥 아니 이게뭐야
입력 받을 때 scanf("%d:%d", &h2, &m2); 이렇게 해도 됐었다. 궁금해서 :말고 다른걸 입력하면 어떻게 되나 봤는데 공백이나 %같은 다른 문자 모두 이상하게 입력됐다. 딱 : 이 문자만 가능한 것 같음. 신기해!
'코드포스' 카테고리의 다른 글
[코드포스 Practice4] D. Vasya and Football (0) | 2019.11.20 |
---|---|
[코드포스 Practice4] C. Ohana Cleans Up (0) | 2019.11.20 |
[코드포스 Practice4] A. Summer Camp (0) | 2019.11.19 |
[코드포스 Practice4] 후기 (0) | 2019.11.19 |
[코드포스 Practice3] C. Serval and Toy Bricks (0) | 2019.11.19 |