Connection Status:
Competition Arena > EllysTimeMachine
2016 TCO Algo 1A · 2016-03-24 · by espr1t · Simple Math, String Parsing
Class Name: EllysTimeMachine
Return Type: String
Method Name: getTime
Arg Types: (string)
Problem Statement

Problem Statement

Elly has invented a simple time machine! Unfortunately, it cannot change the time by more than several hours. But sometimes several hours is all a person needs...

The time machine has a wall clock with two hands: a small hand that shows the hour and a large hand that shows the minutes. Both hands move in discrete steps. The minute hand moves to show the correct time whenever the number of minutes reaches a multiple of 5. The hour hand moves to show the correct time each whole hour. This means that at any moment, the hour hand points to one of the numbers 01, 02, 03, ..., 11, and 12. Additionally, at any moment, the minute hand also points to one of those numbers, but we interpret them as minutes: :05, :10, :15, ..., :55, and :00.

The time machine behaves in a peculiar way: when activated, it jumps to such a time that the two hands on the clock switch positions. For example, suppose the current time is 11:20. On the clock, the hour hand points to 11 and the minute hand points to 04 (that represents :20). As Elly activated the time machine, the hands switched positions: now the hour hand points to 04 and the minute hand points to 11. Thus, the time machine jumped to the time 04:55. See the sample test cases for other examples of how the time machine works.

You are given the current time in the String time in the format "HH:MM", where HH are the hours (a two-digit number between 01 and 12, inclusive), and MM are the minutes (a two-digit number between 00 and 55, inclusive). Compute the new time after the time machine is activated. Return that time in the same format.

Notes

  • Please note that the required time formatting always requires two digits both for the hour and the minutes (i.e. the numbers are padded with leading zeroes when needed).

Constraints

  • time will contain exactly 5 characters and will be formatted as "HH:MM".
  • HH will be one of {01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12}.
  • MM will be one of {00, 05, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55}.
Examples
0)
"11:20"
Returns: "04:55"

The example from the problem statement.

1)
"02:25"
Returns: "05:10"
2)
"06:30"
Returns: "06:30"
3)
"05:55"
Returns: "11:25"
4)
"03:45"
Returns: "09:15"

Submissions are judged against all 149 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class EllysTimeMachine with a public method string getTime(string time) · 149 test cases · 2 s / 256 MB per case

Submitting as anonymous