Fractals P67430


Statement
 

pdf   zip

Consider an n×mn \times m matrix of chars MM, which may include ‘.’, ‘X’, ‘p’ and ‘n’. Define the “negative” of MM 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 MM to create some kind of fractals, by repeatedly replacing each character cc of the current matrix by an n×mn \times m matrix, with these rules:

  • If c=c =.’, replace cc by an n×mn \times m matrix with all ‘.’.

  • If c=c =X’, replace cc by an n×mn \times m matrix with all ‘X’.

  • If c=c =p’, replace cc by MM.

  • If c=c =n’, replace cc by the negative of MM.

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 kk times?

Input

Input consists of several cases. Every case begins with nn, mm and kk, followed by an n×mn \times m matrix MM as explained above. Assume that nn and mm are between 1 and 100, and k1k \ge 1.

Output

Print kk 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 10610^6 chars.

Public test cases
  • 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
    **********
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++