zoukankan      html  css  js  c++  java
  • codeforces 622B B. The Time

    B. The Time
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.

    Note that you should find only the time after a minutes, see the examples to clarify the problem statement.

    You can read more about 24-hour format here https://en.wikipedia.org/wiki/24-hour_clock.

    Input

    The first line contains the current time in the format hh:mm (0 ≤ hh < 24, 0 ≤ mm < 60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).

    The second line contains integer a (0 ≤ a ≤ 104) — the number of the minutes passed.

    Output

    The only line should contain the time after a minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).

    See the examples to check the input/output format.

    Examples
    input
    23:59
    10
    output
    00:09
    input
    20:20
    121
    output
    22:21
    input
    10:10
    0
    output
    10:10

     题意:问从起点时间经过所给的时间,终点时间是多少;

    思路:将时间都转换成分钟;

    AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    char str[8];
    int a;
    int main()
    {
        scanf("%s",str);
        scanf("%d",&a);
        int x1,x2;
        x1=(str[0]-'0')*10+(str[1]-'0');
        x2=(str[3]-'0')*10+(str[4]-'0');
        //cout<<x1<<":"<<x2<<"
    ";
        x2+=a;
        x1+=x2/60;
        x2%=60;
        x1%=24;
        if(x1<10)printf("0%d:",x1);
        else printf("%d:",x1);
        if(x2<10)printf("0%d
    ",x2);
        else printf("%d
    ",x2);
        return 0;
    }
  • 相关阅读:
    两数相加(B站看视频总结)
    正则表达式基础1
    C语言程序的错误和警告
    C语言运算符优先级和结合性一览表
    逻辑运算符及其优先级,C语言逻辑运算符及其优先级详解
    C 语言实例
    电脑不显示桌面怎么办?
    135编辑器安卓客户端
    C语言实例-大小写字母间的转换
    C 语言实例
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5221728.html
Copyright © 2011-2022 走看看