#K68327. Conway's Game of Life Simulation
Conway's Game of Life Simulation
Conway's Game of Life Simulation
This problem requires you to simulate Conway's Game of Life for a given number of generations on an initial board configuration.
The rules of the game are as follows:
- If a cell is live ('X') and has fewer than $2$ live neighbors, it dies (underpopulation).
- If a cell is live and has $2$ or $3$ live neighbors, it stays alive.
- If a cell is live and has more than $3$ live neighbors, it dies (overpopulation).
- If a cell is dead ('.') and has exactly $3$ live neighbors, it becomes live (reproduction).
You are given the size of the board and the number of generations to simulate. Your task is to output the final board configuration after the simulation.
The board is represented as a grid of characters, where each character is either a dot ('.') indicating a dead cell or an 'X' indicating a live cell.
inputFormat
The first line of input contains three space-separated integers:
- n: the number of rows in the board.
- m: the number of columns in the board.
- g: the number of generations to simulate.
This is followed by n lines, each containing a string of length m representing a row of the board. Each character in the string is either '.' (a dead cell) or 'X' (a live cell).
outputFormat
Output the final board configuration after g generations. The output should consist of n lines, each line being a string of length m representing the state of each row in the board.
## sample4 8 3
........
....X...
...XX...
........
........
...XX...
...XX...
........
</p>