Educational Codeforces Round 7--B. The Time

本文介绍了一种解决24小时格式时间计算问题的方法。给定当前时间和一个分钟数,文章详细阐述了如何准确计算出经过该分钟数后的新时间,并提供了完整的C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

Sample test(s)
input
23:59
10
output
00:09
input
20:20
121
output
22:21
input
10:10
0
output
10:10
大体题意:
给你现在的时间,在给你一个分钟数n,求现在的时间过上n分钟后的时间。
思路很清晰:
1.把分钟数n先变成   小时:分钟  的格式。
2.在对应和现在的时间相加。分钟满60进1,小时对24取余即可。

代码如下:
#include<bits/stdc++.h>
#define mem(x) memset(x,0,sizeof(x));
#define mem1(x) memset(x,-1,sizeof(x));
using namespace std;
const double eps = 1e-8;
const int INF = 1e8;
const int maxn = 10000 + 10;
const int maxt = 100 + 10;
typedef long long ll;
typedef unsigned long long llu;
int main()
{
    int h,m;
    while(scanf("%d:%d",&h,&m) == 2){
        int mm;
        cin >> mm;
        int lef_h = mm/60;
        int lef_m = mm-(mm/60)*60;
        int flag = 0;
        int res_m,res_h;
        res_m=m+lef_m;
        if (res_m>=60){
            flag=res_m/60;
            res_m=res_m%60;
        }
        res_h=(h+lef_h+flag)%24;
        cout << res_h/10 << res_h%10 << ":"<<res_m/10 << res_m%10 << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值