#C2259. TimeSpan Operations and Normalization

    ID: 45555 Type: Default 1000ms 256MiB

TimeSpan Operations and Normalization

TimeSpan Operations and Normalization

In this problem you are required to implement a TimeSpan class that represents a time span with hours, minutes, and seconds. The class must support normalizing the time span so that the minutes and seconds are always in the interval (0 \le minutes, seconds < 60) (using borrowing when negative values occur) and it must support addition and subtraction of two time spans.

The program should read from standard input where the first line contains a command which is one of "normalize", "add", or "subtract". For the "normalize" command, a single time span is provided on the next line in the format: . For the "add" and "subtract" commands, two time spans are provided (each on a separate line). The output should be the resulting time span in the format: printed on a single line.

For example:

  • For input: normalize\n1 61 121 The normalized time span is: 2 3 1

  • For input: add\n1 40 35\n0 30 50 The result of addition is: 2 11 25

  • For input: subtract\n1 40 35\n0 30 50 The result of subtraction is: 1 9 45

Implement the TimeSpan class and the arithmetic operations accordingly with proper normalization.

inputFormat

Input is read from standard input (stdin). The first line contains a command which is one of "normalize", "add", or "subtract".

For the "normalize" command, the next line has three integers: hours, minutes, seconds. For the "add" and "subtract" commands, the next two lines (each) contain three integers representing a time span in the order hours, minutes, seconds.

outputFormat

Output the resulting time span to standard output (stdout) as three integers: hours, minutes, seconds separated by a space on a single line.## sample

normalize
1 61 121
2 3 1

</p>