Time Warp
Time limit3sMemory limit256 MB
Given phrases like 'a after b', find the nearest clock time after or before the hour when the directed hand angle equals a.
- Level
Medium5 of 10
- Topics
- Math
- Solved
- No attempts yet
Problem
Tim tells the time in his own way. Ask him and he might answer 20 after 8, which sounds ordinary, or 90 after 8 and 126 til 4, which do not.
Tim's rule is this. 20 after 8 is the first time after 8 o'clock at which the hour hand and the minute hand make an angle of 20 degrees. 126 til 4 is the time closest to 4 o'clock among the times before 4 o'clock at which the two hands make an angle of 126 degrees.
Both hands move continuously at a constant speed. Write a program that converts Tim's phrases into ordinary times.
Input
The first line has the number of test cases . Each of the next lines holds one string of the form a after b or a til b, where and are integers with and .
The angle is measured starting at the hour hand and moving clockwise until reaching the minute hand. At 9 o'clock the hands make an angle of 90 degrees, and at 3 o'clock they make an angle of 270 degrees.
after means only a time later than o'clock, and til means only a time earlier than o'clock. If the angle is already degrees at o'clock, that exact moment is not an answer.
Output
For each test case print one line of the form Case i: h:m:s, where is the test case number starting at 1, and , and are the hour, the minute and the second closest to the time you found.
The hour satisfies and is printed without padding. Always print two digits for the minute and two digits for the second.