Grid Colouring |
A set of contours is represented on a two dimensional grid as illustrated in the sample below. The contours are made of any printable character different than space and `_' (underscore). In the sample this character is `X'. All the other points of the grid are represented by spaces and marking characters.
A grid zone is defined as the set of points enclosed within a closed contour
such that any two zone points can be connected by a path which does not cross
any contour and whose segments run vertically or horizontally. A zone is
marked if it contains identical characters, called marking characters,
different than space and the character used to draw the grid contours. No
zone can contain different marking characters. However, observe that while all
the contours are drawn with the same character, the markings of different zones
can be different. A zone is unmarked if it contains only spaces. Any grid zone
can be either marked or unmarked and the marking characters can appear inside
grid zones only.
Write a program to fill all the marked zones on each grid read from the input
file. A marked zone is filled with its marking character, as shown in the sample.
XXXXXXXXXXXXXXXXXXXX X X X X # # XXXXXXXX / X X X X XXXXXXXXXXXXXXXXXXXX _____________________________ XXXXXXXXXXXX XXXXXX X # XXX XXX X X X XX X X X X X X X XXXXXXX XXXXXXX X XX X X X XXXX XXXXXXXX XX XXXX X X / X X X X / X XXXXXXXXXXXXX XXXXXXXX _____________________________
XXXXXXXXXXXXXXXXXXXX X######X///////////X X######XXXXXXXX////X X#############X////X XXXXXXXXXXXXXXXXXXXX _____________________________ XXXXXXXXXXXX XXXXXX X###########XXX XXX X X X##XX#########X X X X X##X X##XXXXXXX XXXXXXX X###XX###X X#######X XXXX XXXXXXXX XX#####XXXX##X X//////X X###########X X//////X XXXXXXXXXXXXX XXXXXXXX _____________________________