This exercise is a continuation of the exercise problem://problemsjutge.org:problems/p1/roura/vida-1.pbm
Let be a matrix with bacteria at the initial time, and let , , , … be the matrices at the times 1, 2, 3, … Write a program that, given , finds the cycle that is obtained starting at , that is, the first and shortest sequence of matrices such that . Suppose .
Input consists of the description of the matrix
:
two strictly positive natural numbers
and
,
followed by
lines, each one with
characters: ‘B’ if the position has a bacterium, and
‘.’ if the position is empty.
Print the matrices of the cycle separated by an empty line.
Input
7 7 ....BBB .B.BBBB .B.BBBB ..BBBBB .B.BBBB .B.BBBB ....BBB
Output
....... ....... ....... BBB.... ....... ....... ....... ....... ....... .B..... .B..... .B..... ....... .......
Input
2 2 BB ..
Output
.. ..
Input
10 10 .......... ...BBBB... ...B..B... .BBB..BBB. .B......B. .B......B. .BBB..BBB. ...B..B... ...BBBB... ..........
Output
.......... ...BBBB... ...B..B... .BBB..BBB. .B......B. .B......B. .BBB..BBB. ...B..B... ...BBBB... .......... ....BB.... ...BBBB... .......... .B.B..B.B. BB......BB BB......BB .B.B..B.B. .......... ...BBBB... ....BB.... ...B..B... ...B..B... ..BB..BB.. BBB....BBB .......... .......... BBB....BBB ..BB..BB.. ...B..B... ...B..B...