#t31. 时间计算问题

时间计算问题

Time Calculation

Problem Description

Sometimes people represent a time with four digits, for example 11061106 means 1111 o'clock and 66 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 55:3030 is written as 530530; 00:3030 is written as 030030. Note that the second number (the elapsed minutes) may be greater than 6060, and may also be negative.

Input Format

The input gives 22 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 — 55:3030 is written as 530530 and 00:3030 is written as 030030. The elapsed minutes may be greater than 6060 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 00 and 2323, minute between 00 and 5959).
  • The elapsed minutes mm satisfy −1440<m<1440-1440 < m < 1440.
  • The problem guarantees the start time and end time are on the same day.

Hint

  • Split the four-digit time tt into hour and minute with / 100 and % 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:30 must be printed as 030 — the minute part is padded with a leading zero; look up setw(2) << setfill('0') (only the minute needs padding).
  • Check against the sample: 1120 110 → 1310.