Codeforces Round #544 (Div. 3) A. Middle of the Contest

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\n",m1); else printf("%d\n",m1); 
    //printf("%d:%d\n",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\n",t1/60,t1%60);
    //cout << "Hello world!" << endl;
    return 0;
}

原来输出可以这样的啊(滑稽),真好用.
算法也很清晰,完美.

转载于:https://www.cnblogs.com/-yjun/p/10503210.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值