Input File Name: A.DAT
Program Source File: A.PAS or A.C or A.CPP
A set of contours is represented on a two dimensional grid as illustrated in figure 1. The contours are made of any printable character different than space and _ (underscore). In figure 1 this character has the decimal code 219. 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 figure 1.
On input, each grid is terminated by a separation line full of underscores _. There are at most 30 lines and at most 80 characters in a line for each grid. The lines can be of different length.
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. Figure 1 is an example of the program input and output for two simple grids.