Consider an
matrix of chars
,
which may include ‘.’, ‘X’, ‘p’
and ‘n’. Define the “negative” of
as the matrix result of replacing each ‘.’ by
‘X’, each ‘X’ by ‘.’, each
‘p’ by ‘n’, and each ‘n’ by
‘p’. For instance, the negative of
XpX .n.
.n. XpX
is
We can use to create some kind of fractals, by repeatedly replacing each character of the current matrix by an matrix, with these rules:
If
‘.’, replace
by an
matrix with all ‘.’.
If
‘X’, replace
by an
matrix with all ‘X’.
If
‘p’, replace
by
.
If
‘n’, replace
by the negative of
.
With the example above, after one step we get
XXXXpXXXX
XXX.n.XXX
....n....
...XpX...
and after two steps we get
XXXXXXXXXXXXXpXXXXXXXXXXXXX
XXXXXXXXXXXX.n.XXXXXXXXXXXX
XXXXXXXXX....n....XXXXXXXXX
XXXXXXXXX...XpX...XXXXXXXXX
.............n.............
............XpX............
.........XXXXpXXXX.........
.........XXX.n.XXX.........
Can you simulate this process times?
Input consists of several cases. Every case begins with , and , followed by an matrix as explained above. Assume that and are between 1 and 100, and .
Print
matrices for each case: the result after one step, two steps, etc.
Separate these matrices by blank lines. End each case with 10 asteriscs.
When printing the results, replace each ‘p’ by
‘X’, and each ‘n’ by ‘.’. With
the given cases, no result will have more than
chars.
Input
2 3 2 XpX .n. 1 1 1 n 1 2 4 pn 2 3 2 p.p ppp
Output
XXXXXXXXX XXX...XXX ......... ...XXX... XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXX...XXXXXXXXXXXX XXXXXXXXX.........XXXXXXXXX XXXXXXXXX...XXX...XXXXXXXXX ........................... ............XXX............ .........XXXXXXXXX......... .........XXX...XXX......... ********** X ********** X..X X..X.XX. X..X.XX..XX.X..X X..X.XX..XX.X..X.XX.X..XX..X.XX. ********** X.X...X.X XXX...XXX X.XX.XX.X XXXXXXXXX X.X...X.X.........X.X...X.X XXX...XXX.........XXX...XXX X.XX.XX.X.........X.XX.XX.X XXXXXXXXX.........XXXXXXXXX X.X...X.XX.X...X.XX.X...X.X XXX...XXXXXX...XXXXXX...XXX X.XX.XX.XX.XX.XX.XX.XX.XX.X XXXXXXXXXXXXXXXXXXXXXXXXXXX **********