579 - Clock Hands

The history of clocks is fascinating, but unrelated to this problem. In
this problem, you are asked to find the angle between the minute hand
and the hour hand on a regular analog clock. Assume that the second
hand, if there were one, would be pointing straight up at the 12. Give
all angles as the smallest positive angles. For example 9:00 is 90
degrees; not -90 or 270 degrees.

Input

The input is a list of times in the form ‘H:M’, each on their own line,
with 1 <= H <= 12 and 00 <= M <= 59. The input is terminated with the
time ‘0:00’. Note that H may be represented with 1 or 2 digits (for 1–9
or 10–12, respectively); M is always represented with 2 digits (the
input times are what you typically see on a digital clock).

Output

The output displays the smallest positive angle in degrees between the
hands for each time. The answer should between 0 degrees and 180 degrees
for all input times. Display each angle on a line by itself in the same
order as the input. The output should be rounded to the nearest 1/1000,
i.e., three places after the decimal point should be printed.

Problem information

Author: Carlos de Salles

Generation: 2026-01-25T22:53:34.797Z

© Jutge.org, 2006–2026.
https://jutge.org
