#K59967. Game of Life Simulation
Game of Life Simulation
Game of Life Simulation
In this problem, you are given an initial state of a rectangular grid and a number of time steps, (T). The grid represents cells which can be either alive (1) or dead (0). You are required to simulate (T) iterations of Conway's Game of Life. The rules for the simulation are as follows:
- Any live cell with fewer than two live neighbors dies (underpopulation).
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies (overpopulation).
- Any dead cell with exactly three live neighbors becomes a live cell (reproduction).
The neighbors of a cell are the 8 cells surrounding it vertically, horizontally, and diagonally.
Your task is to output the state of the grid after (T) iterations.
Input/Output Format: The grid and (T) are provided via standard input. The final grid state should be printed to standard output.
inputFormat
The first line of input contains three space-separated integers (m), (n) and (T), where (m) and (n) represent the number of rows and columns of the grid, and (T) indicates the number of iterations to simulate. This is followed by (m) lines, each containing (n) space-separated integers (either 0 or 1), representing the initial state of the grid.
outputFormat
Output the final state of the grid after (T) iterations. The output should consist of (m) lines, each containing (n) space-separated integers representing the state of the grid.## sample
3 3 1
0 1 0
0 0 1
1 1 1
0 0 0
1 0 1
0 1 1
</p>