Fractals P67430


Statement
 

pdf   zip

thehtml

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

  • If c = ‘.’, replace c by an n × m matrix with all ‘.’.
  • If c = ‘X’, replace c by an n × m matrix with all ‘X’.
  • If c = ‘p’, replace c by M.
  • If c = ‘n’, replace c by the negative of M.

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

Input

Input consists of several cases. Every case begins with n, m and k, followed by an n × m matrix M as explained above. Assume that n and m are between 1 and 100, and k ≥ 1.

Output

Print k 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 106 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++