Czech ACM Student Chapter
Czech Technical University in Prague
Charles University in Prague
Technical University of Ostrava
acm
ˇ a
Slovak University of Technology
Pavol Jozef Saf´rik University in Koˇice
s
cz
ˇ
University of Zilina
Masaryk University
Matej Bel University in Bansk´ Bystrica
a
University of West Bohemia
CTU Open Contest 2011
Analog Clock Display
analog.c, analog.C, analog.java, analog.p
Our old clock chimed four o'clock, and with that last sound they dissolved into a pile of sticks.
Since the craftsmanship necessary to fix them was forgotten and lost long time ago, we decided
to replace them by a computer program.
An easy task, you say? There is one more little thing to mention: Recent studies of extrater-
restrial aliens showed that they live in a digital world and therefore they are unable to read the
traditional clock face with two moving hands. It is simply something beyond their technical ca-
pabilities. Therefore, the Security Board decided that our new clock must use such a traditional
"analog" display to protect the time information against non-humans.
Input Specification
The input contains several instances, each of them consisting of one row containing two integers
H (0 H 23) and M (0 M 59) separated by a colon. M is always given with two digits,
H has one or two digits, i.e., no leading zero unless H = 0.
The last test case is followed by the word "END".
Output Specification
For each input instance H :M , draw an "ASCII art" clock face depicting the time of H hours
and M minutes according to the following specification.
The face frame is a square, with 51 characters per each side. These characters are uppercase
letters "X", with the exception of four corners and every tenth character, which is always "@".
The numbers 3, 6, 9, and 12 are centered at their appropriate sides, with exactly one space
between them and the frame. There is one space between digits 1 and 2. The center of the face
always contains the asterisk symbol: "*". All visually "empty" characters are simple spaces.
Two hands are the only elements of the clock face that depend on the time. In the following
description of the placement of the hands, we assume that each character (both space or occu-
pied) is a 1 × 1 square and the start (0, 0) of the coordinate system is placed in the center of the
square containing the asterisk symbol, with the first axis pointing to the right, and the second
axis upwards.
The hour hand is drawn as a line segment of length 15 starting at (0, 0). The hand points upwards
at 12 o'clock and moves uniformly by the same angle each minute. Similarly, the minute hand
is drawn as a line segment of length 21 starting at (0, 0). That hand points upwards every
hour and also moves uniformly by the same angle every minute in the clockwise direction (what
a surprise). The minute hand is considered to be above the hour hand, i.e., the characters
representing the hour hand may be hidden by parts of the minute hand.
A line whose angle from the vertical direction is D degrees should be drawn as follows. If
0 D 45, one character is printed for each row i at (integer) coordinates (ni, i) as close
as possible to the point (xi, i) that lies exactly on the geometric line (xi is a real number). If
45 D 90, there is one character printed for each column i at the (integer) coordinates (i, ki ),
the closest possible square to the (real) point (i, yi) on the line.
The character displayed to draw the line at some position (i, j) depends on the two "neighboring"
characters of the line. The character is
·
minus symbol "-" if there are also characters at both positions (i - 1, j) and (i + 1, j),
·
pipe symbol "|" if there are also characters at both positions (i, j - 1) and (i, j + 1),
·
backslash symbol "\" if there are characters at positions (i - 1, j + 1) and (i + 1, j - 1),
·
slash symbol "/" if there are also characters at positions (i - 1, j - 1) and (i + 1, j + 1),
·
lowercase letter "o" otherwise.
A line segment of length S starting at (0, 0) is drawn by displaying characters in the same way
as drawing the corresponding line, but we only print such characters whose distance between
the center of the square and the origin (0, 0) is at most S, 0 < |(0, 0), (i, j)| ≤ S, and only in one
direction of the line.
Please see the sample output to resolve any ambiguities in the above description. Print one
empty line after each clock face.
Sample Input
1:03
14:27
END
Output for Sample Input
@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@
X
X
X
12
X
X
X
X
X
X
o
X
X
|
X
X
|
X
X
o
X
X
o
X
@
|
@
X
o
X
X
o
X
X
|o
X
X
oo
X
X
oo
X
X
|o
X
X
o/
X
X
oo
X
X
|o
X
@
o/
@
X
oo
X
X
|o
X
X
o
X
X
oo
X
X9
*
3X
X
X
X
X
X
X
X
X
@
@
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
@
@
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
6
X
X
X
@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@
@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@
X
X
X
12
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
@
@
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
@
@
X
o--
X
X
o-o
X
X
o-o
X
X
o--o
X
X9
*o
3X
X
o
X
X
o
X
X
|
X
X
o
X
@
o
@
X
|
X
X
o
X
X
o
X
X
|
X
X
o
X
X
o
X
X
|
X
X
o
X
X
o
X
@
|
@
X
o
X
X
o
X
X
|
X
X
|
X
X
o
X
X
X
X
X
X
6
X
X
X
@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@XXXXXXXXX@
Notice
If you get a presentation error for this problem, it will likely mean wrong formatting, usage of
wrong characters, bad clock size, missing spaces, etc. On the other hand, wrong answer typically
means incorrect content of the clock face, although it is technically also a "presentation" issue.