zoukankan      html  css  js  c++  java
  • 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
    ",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;
    }
    

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

  • 相关阅读:
    SAP C4C OBN(Object Based Navigation)不能工作的原因分析
    使用SAP C4C自定义BO association创建动态下拉列表
    如何使用SAP HANA Studio的PlanViz分析CDS view性能问题
    如何使用jMeter测试SAP OData服务并发访问时的性能
    OData服务在SAP CRM,Cloud for Customer和S/4HANA上的实现比较
    SAP UI5和Vue的数据双向绑定实现原理比较
    在SAP WebClient UI里显示倒数计时的UI
    【年度重磅】2020华为云社区年度技术精选合集,700页+免费下载!
    面试必问:如何实现Redis分布式锁
    聊聊架构模式的变迁:从分层架构到微服务架构
  • 原文地址:https://www.cnblogs.com/-yjun/p/10503210.html
Copyright © 2011-2022 走看看