You are viewing a single comment's thread. Return to all comments →
C# Solution:
public static int[,] DetonationArealMatrix(int[,] matrix) { int[,] m2 = new int[matrix.GetLength(0), matrix.GetLength(1)]; for (int i = 0; i < matrix.GetLength(0); i++) for (int j = 0; j < matrix.GetLength(1); j++) if (matrix[i, j] == 1) { m2[i, j] = 1; if (i != 0) m2[i - 1, j] = 1; if (j != 0) m2[i, j - 1] = 1; if (i != matrix.GetLength(0) - 1) m2[i + 1, j] = 1; if (j != matrix.GetLength(1) - 1) m2[i, j + 1] = 1; } return m2; } public static int[,] DetonateMatrix(int[,] matrix) { int[,] m2=new int[matrix.GetLength(0),matrix.GetLength(1)]; for (int i = 0; i < matrix.GetLength(0); i++) for (int j = 0; j < matrix.GetLength(1); j++) m2[i, j] = 1 - matrix[i, j]; return m2; } public static void PrintMatrix(int[,] matrix) { for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { if (matrix[i, j] == 1) Console.Write('O'); else Console.Write('.'); } Console.WriteLine(); } } static void Main(string[] args) { int[] arr = new int[3]; arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int R = arr[0]; int C = arr[1]; int N = arr[2]; int[,] matrix = new int[R, C]; for (int i = 0; i < R; i++) { string str = Console.ReadLine(); for (int j = 0; j < str.Length; j++) if (str[j] == 'O') matrix[i, j] = 1; } if (N == 1) PrintMatrix(matrix); else if (N % 2 == 0) for (int i = 0; i < R; i++) Console.WriteLine(new string('O', C)); else { int[,] matrix2 = new int[R, C]; matrix = DetonationArealMatrix(matrix); matrix = DetonateMatrix(matrix); matrix2 = DetonationArealMatrix(matrix); matrix2 = DetonateMatrix(matrix2); if (((N - 3) / 2) % 2 == 1) PrintMatrix(matrix2); else PrintMatrix(matrix); } }
Seems like cookies are disabled on this browser, please enable them to open this website
The Bomberman Game
You are viewing a single comment's thread. Return to all comments →
C# Solution: