| Contour Painting |
A contour of points is represented on a two dimensional (2D) grid as illustrated in figure 1. The points of the contour are specified by the same character which can be any printable character, different than `*',`#',`_' and space. In figure 1 this character is `X'. All the other points of the grid are represented by spaces. The contour is connected, i.e. any two points on the contour can be reached from one another by traveling vertically, horizontally and diagonally. Moreover, it is considered that a contour can close a single non empty zone of grid points.
012345678901234567890123456789
------------------------------
0|
1| XXXXXXXXXX
2| XXXX XX
3| X X
4| X X XXXXXXX
5| XXXXXXXX XX
6| X X XXXXXXX
7| X X
8| XXXX XX
9| XXXXXXXXXX
0|
Figure 1: A contour on a 2D grid
The character `#' represents the colour used to paint the contour as illustrated in figure 3. The paint is added on one side of the contour in such a way that each contour point of the painted side has at least one `#' neighbour horizontally or vertically as shown in figure 2:
####
### X### XXXX#
XXX XXXX X#
flat zone concave corner convex corner
Figure 2: Cases of point painting
A contour can be painted either from inside or from outside. The painting side is specified by the presence of the character `*' inside or outside the contour as shown in figure 3. Notice that the star is removed from the grid once the painting is done.
XXXXXXXXXX XXXXXXXXXX interior
XXXX XX XXXX#######XX painting
X * X X### # ##X
X X XXXXXXX X######X# #XXXXXXX
XXXXXXXX XX XXXXXXXX# #######XX
X X XXXXXXX X######X# #XXXXXXX
X X X### # ##X
XXXX XX XXXX#######XX
XXXXXXXXXX XXXXXXXXXX
* ########## exterior
XXXXXXXXXX #XXXXXXXXXX## painting
XXXX XX #XXXX XX#
X X #X X######
X X XXXXXXX #X X XXXXXXX##
XXXXXXXX XX #XXXXXXXX XX#
X X XXXXXXX #X X XXXXXXX##
X X #X X######
XXXX XX #XXXX XX#
XXXXXXXXXX #XXXXXXXXXX##
##########
Figure 3: Painting a closed contour
Your problem is to write a program which: reads from a text
file a number n and n grids, each grid containing a single
contour and a single star, paints each grid according to the
position of the star and outputs the painted grids to a text
file. Each contour is placed on its grid in such a way that it is
fully surrounded by free grid points (spaces).
3
XXXXXXX
X * X
XXXXXXX
__________
XXXXXXXXXX
XXXX XX
X X
X X XXXXXXX
XXXXXXXX XX
X X XXXXXXX
X X
XXXX *XX
XXXXXXXXXX
__________
XXXXXXXXXX
* XXXX XX
X X
X X XXXXXXX
XXXXXXXX XX
X X XXXXXXX
X X
XXXX XX
XXXXXXXXXX
__________
XXXXXXX
X#####X
XXXXXXX
__________
XXXXXXXXXX
XXXX#######XX
X### # ##X
X######X# #XXXXXXX
XXXXXXXX# #######XX
X######X# #XXXXXXX
X### # ##X
XXXX#######XX
XXXXXXXXXX
__________
##########
#XXXXXXXXXX##
#XXXX XX#
#X X######
#X X XXXXXXX##
#XXXXXXXX XX#
#X X XXXXXXX##
#X X######
#XXXX XX#
#XXXXXXXXXX##
##########
__________