using System; using System.Collections.Generic; class Crossfire { static void Main() { string input = Console.ReadLine(); string[] matrixParams = input.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); int rows = int.Parse(matrixParams[0]); int cols = int.Parse(matrixParams[1]); int[, ] matrix = new int[rows, cols]; for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { matrix[i, j] = (j + 1) + (i * rows); } } int[][] resultMatrix = new int[rows][]; for (int i = 0; i < matrix.GetLength(0); i++) { resultMatrix[i] = new int[matrix.GetLength(1)]; for (int j = 0; j < matrix.GetLength(1); j++) { resultMatrix[i][j] = matrix[i, j]; } } while (true) { string command = Console.ReadLine(); if (command == "Nuke it from orbit") { break; } string[] commandParams = command.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); int centerRow = Math.Abs(int.Parse(commandParams[0])); int centerCol = Math.Abs(int.Parse(commandParams[1])); int radius = int.Parse(commandParams[2]); //Checking if the center coordinates are in the matrix and if so, putting the center of the cross if ((centerRow >= 0 && centerRow < resultMatrix.Length) && (centerCol >= 0 && centerCol < resultMatrix[centerRow].Length)) { //Setting the center of the cross resultMatrix[centerRow][centerCol] = 0; //Creating the cross based on the radius, starting from the center of the cross and going up, down, left and right for (int i = 0; i <= radius; i++) { //Going up from the center of the cross int cellUp = centerRow - i; if (cellUp >= 0) { if (centerCol < resultMatrix[cellUp].Length) { resultMatrix[cellUp][centerCol] = 0; } } //Going down from the center of the cross int cellDown = centerRow + i; if (cellDown < resultMatrix.Length) { if (centerCol < resultMatrix[cellDown].Length) { resultMatrix[cellDown][centerCol] = 0; } } //Going left from the center of the cross int cellLeft = centerCol - i; if (cellLeft >= 0) { resultMatrix[centerRow][cellLeft] = 0; } //Going right from the center of the cross int cellRight = centerCol + i; if (cellRight < resultMatrix[centerRow].Length) { resultMatrix[centerRow][cellRight] = 0; } } //Adding the remaining cells into a list List> remainingCells = new List>(); for (int j = 0; j < resultMatrix.Length; j++) { remainingCells.Add(new List()); for (int k = 0; k < resultMatrix[j].Length; k++) { if (resultMatrix[j][k] != 0) { remainingCells[j].Add(resultMatrix[j][k]); } } } //Re-initializing the result matrix and filling it with the values in the list resultMatrix = new int[remainingCells.Count][]; for (int j = 0; j < resultMatrix.Length; j++) { resultMatrix[j] = new int[remainingCells[j].Count]; for (int k = 0; k < resultMatrix[j].Length; k++) { resultMatrix[j][k] = remainingCells[j][k]; } } } } for (int i = 0; i < resultMatrix.Length; i++) { for (int j = 0; j < resultMatrix[i].Length; j++) { Console.Write(resultMatrix[i][j] + " "); } Console.WriteLine(); } } }