BadClock
SRM 172 · 2003-11-20 · by Eeyore
Problem Statement
According to Lewis Carroll, a clock that has stopped is more accurate than one that is five minutes behind. He argues that the former is right twice a day, whereas the latter never shows the correct time. Then again, a clock that is always five minutes behind is in a sense perfectly accurate, and therefore an extraordinary specimen. More usually, a clock is ahead or behind because it runs at the wrong rate, so that its absolute discrepancy from the true time is steadily changing. If left unregulated, such a clock will show the true time at regular but perhaps lengthy intervals.
You are given two
Notes
- If hourlyGain is negative, the clock falls behind by a fixed number of seconds every hour.
- It is not the case that the clock makes discrete jumps every so often. Rather, the hands of the clock are moving smoothly and continuously at a constant rate that is too slow or too fast relative to the true time.
Constraints
- trueTime and skewTime each contain exactly eight characters in the format "hh:mm:ss", where the substring "hh" is a zero-padded integer between 1 and 12, inclusive, and "mm" and "ss" are zero-padded integers between 0 and 59, inclusive
- hourlyGain is either between -1800 and -1, inclusive, or between 1 and 3600, inclusive
"07:07:07" "07:07:07" 1776 Returns: 0.0
The clock is already showing the true time.
"11:59:58" "12:03:28" -3 Returns: 70.0
This clock loses three seconds every hour, and will catch up with the true time in exactly 70 hours.
"12:03:28" "11:59:58" 3 Returns: 70.0
This clock gains three seconds per hour.
"03:03:02" "03:01:47" 5 Returns: 15.0
"03:03:02" "03:01:47" -5 Returns: 8625.0
Submissions are judged against all 121 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BadClock with a public method double nextAgreement(string trueTime, string skewTime, int hourlyGain) · 121 test cases · 2 s / 256 MB per case