Welcome to ZOJ
 Problem Sets Information Select Problem Runs Ranklist
ZOJ Problem Set - 1209
April Fool's Joke

Time Limit: 2 Seconds      Memory Limit: 65536 KB

High on the wall of the church tower in a small village in Transylvania is an analog clock. It has an hour hand and a minute hand and a conventional 12-hour dial. The clock's mechanism advances both hands by the appropriate amount once every minute.

During the night preceding April Fool's Day, two mischievous and mechanically skilled persons embark on a clandestine expedition. They ascend the church tower and interchange ("swap") the clock's two hands, so that each hand is pointing in the direction in which the other hand should be pointing.

For example, suppose the true time is 7:18. Then we have the scenario depicted in Figures 1a and 1b:

The observer who looks at the swapped clock at this time (assuming he/she has no preconceived notion of what time it ought to be) will say: "It is 3:37."

Just two minutes later, at 7:20, however, the scenario will be very different, as shown in Figures 2a and 2b:

At this point, the observer who looks at the swapped clock will notice that the hour hand is pointing directly at the 4 o'clock position, so it ought to be very close to 4 o'clock. But the minute hand indicates that it is 37 minutes past the hour, which is not compatible with the hour hand's position. In this case, we say that the swapped clock's configuration is not valid.

Here is an example of the input for your program:

7              18
7              19
7              20
3               0
3               2
4              30
12             15

Each line of the input contains two integers (separated by one or more blank spaces) that specify the hours and minutes of the current true time, respectively. The value of hours will be in the range 1..12, the value of minutes will be in the range 0..59.

For each line of input, your program will determine whether the swapped clock's hands will form a valid configuration, and if so, print out the time shown by the swapped clock.

More specifically, here is the output resulting from the input listed above:

Problem 3 by team x
==============================================================================
True     True     Minutes From   Minutes From   Discrepancy  Swapped  Swapped
Hours  Minutes   Minute Hand In   Hour Hand In    Of Minutes    Hours  Minutes
Swapped Clock  Swapped Clock
==============================================================================
7       18               37             36             1        3       37
7       19               37             48            11        3       37
7       20               37              0            23       --       --
3        0               15              0            15       --       --
3        2               15             24             9       12       15
4       30               23              0            23       --       --
12       15                1              0             1        3        1
==============================================================================
End of problem 3 by team x

The numbers in the first two vertical fields of the output just echo the input.

From the input values, it is straightforward to calculate the position of the minute hand in the swapped clock, which determines a certain number of minutes past the hour, as listed in the third field of the output.

From the input values, it is also straightforward to calculate the position of the hour hand in the swapped clock. The position of the hour hand actually determines hours as well as minutes; the minutes are listed in the fourth field of the output.

The discrepancy between the two results for minutes, listed in the fifth field of the output, is first calculated as the absolute value of the difference between the two results for minutes. This discrepancy, however, cannot exceed 30 minutes, so (as on the third line of numerical output) it may need to be subtracted from 60 minutes.

Results in the third and fourth output fields are rounded to the nearest integer, if necessary. The discrepancy (in the fifth output field) is calculated from the integer values displayed in the third and fourth output fields.

The configuration of the swapped clock is considered to be valid if the discrepancy does not exceed 12 minutes.

In this case, the swapped clock's time is printed in the sixth and seventh fields of the output. The value of minutes displayed in the seventh field is identical to the value displayed in the third field.

Otherwise, two hyphens are displayed in each of the sixth and seventh output fields.

Observe every detail of the output, such as the exact wording of the headers, upper/lower case variations, separator lines (of equal signs) and blank spaces.

A few lines of the above output will be reproduced here with a formatting template:

1         2         3         4         5         6         7
123456789012345678901234567890123456789012345678901234567890123456789012345678
True     True     Minutes From   Minutes From   Discrepancy  Swapped  Swapped
Hours  Minutes   Minute Hand In   Hour Hand In    Of Minutes    Hours  Minutes
Swapped Clock  Swapped Clock
==============================================================================
7       18               37             36             1        3       37

Source: Rocky Mountain 1999
Submit    Status