SlowDigitalClock
SRM 260 · 2005-08-27 · by gepa
Problem Statement
We have a big digital wall clock, but while hanging it on the wall, we mounted it upside-down by mistake (i.e. the display was rotated 180 degrees). To make things worse, the clock has a complicated mechanism inside that makes it go slow when it is upside-down, needing secsPerMinute seconds to advance a minute instead of 60 seconds. Note that even at the moment we hang the clock on the wall, this is not necessarily set at the correct time. The clock itself only displays hours (from 00 to 23) and minutes (from 00 to 59), including any leading zeros.
You are given a
When the clock time is read upside-down, the digits 0, 1, 2, 5 and 8 are the same, 6 is shown as 9 and 9 is shown as 6. The digits 3, 4 and 7 do not show any meaningful digits when read upside-down.
Notes
- You may assume that when the clock display is updated to the next minute, this update takes zero time.
Constraints
- currentTime and clockTime will have exactly 5 characters each, in the form "HH:MM". "HH" will be an integer between 00 and 23, inclusive (including any leading zeros), "MM" will be an integer between 00 and 59, inclusive (including any leading zeros).
- secsPerMinute will be between 61 and 1000, inclusive.
"01:11" "21:09" 61 Returns: "01:12"
At the beginning, the clock shows the upside-down time "60:12" (of course, this is not a valid time, so this can not be the correct time). After 61 seconds, the clock will advance to 21:10, which is read upside-down as: 01:12. Since the correct time at the beginning was 01:11:00, now (61 seconds later) the time is 01:12:01, so (ignoring the seconds) the clock shows the correct time "01:12". The figure below shows the normal clock display when it shows 21:10. The figure below shows the same display upside-down (now showing 01:12).
"01:10" "21:09" 61 Returns: "01:12"
In 120 seconds, the time is 01:12, but the clock still shows 21:10 (which upside-down reads 01:12).
"12:50" "05:21" 125 Returns: "12:50"
The clock already shows the correct time at the beginning (and this remains correct for the next 60 seconds), so currentTime is returned.
"05:46" "23:50" 240 Returns: "11:10"
Be careful when changing days (after 23:59 comes 00:00).
"12:34" "23:45" 197 Returns: "02:11"
The first time that the clock displays the correct time may occur after several days.
"12:34" "23:45" 300 Returns: ""
In this case, the clock never shows the correct time.
"00:00" "01:21" 77 Returns: "15:02"
00:00 01:21 77
Submissions are judged against all 86 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SlowDigitalClock with a public method string firstCorrectTime(string currentTime, string clockTime, int secsPerMinute) · 86 test cases · 2 s / 256 MB per case