#t31. 时间计算问题
时间计算问题
Time Calculation
Problem Description
Sometimes people represent a time with four digits, for example means o'clock and minutes. Your program must compute the end time from a start time and an elapsed duration.
Read two numbers: the first is the current time written as such a four-digit number, and the second is an amount of minutes; compute what time it will be after that many minutes, again written as a four-digit number. When the hour is a single digit there is no leading zero — for example : is written as ; : is written as . Note that the second number (the elapsed minutes) may be greater than , and may also be negative.
Input Format
The input gives integers on one line: the start time as a four-digit number, and the elapsed minutes, separated by a space. Note: in the start time, when the hour is a single digit there is no leading zero — : is written as and : is written as . The elapsed minutes may be greater than or may be negative.
Output Format
Output the end time as at most a four-digit number, with no leading zero on the hour. The problem guarantees that the start time and the end time fall on the same day.
Sample Input
1120 110
Sample Output
1310
Constraints
- The start time is a valid four-digit time (hour between and , minute between and ).
- The elapsed minutes satisfy .
- The problem guarantees the start time and end time are on the same day.
Hint
- Split the four-digit time into hour and minute with
/ 100and% 100. The elapsed minutes may be negative. - Convert everything into "total minutes", do the addition/subtraction, then convert back — that is the least error-prone path.
- There is an output trap:
0:30must be printed as030— the minute part is padded with a leading zero; look upsetw(2) << setfill('0')(only the minute needs padding). - Check against the sample:
1120 110→1310.