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. Input On input, each grid is terminated by a separation line full of underscores ‘’. There are at most 32 lines and at most 80 characters in a line for each grid. The lines can be of different length. Output The standard output file contains the painted grids. Each grid is output in the same format it is read from the input file, including the separation line, blank lines and possible leading or trailing spaces. Sample Input XXXXXXXXXXXXXXXXXXXX XXX X## XXXXXXXX/ X XXX XXXXXXXXXXXXXXXXXXXX


XXXXXXXXXXXX XXXXXX X # XXX XXX X X XXX XXXX X X X XXXXXXX XXXXXXX X XX X X X XXXX XXXXXXXX XX XXXX X X / X XXX/X XXXXXXXXXXXXX XXXXXXXX


2/2 Sample Output 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