Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- List<int[]> matrix = new List<int[]>();
- int counter = 1;
- for (int i = 0; i < array[0]; i++)
- {
- matrix.Add(new int[array[1]]);
- for (int j = 0; j < array[1]; j++)
- {
- matrix[i][j] = counter++;
- }
- }
- string input = Console.ReadLine();
- while (input != "Nuke it from orbit")
- {
- int[] coords = input.Split(' ').Select(int.Parse).ToArray();
- int row = coords[0];
- int col = coords[1];
- int radius = coords[2];
- Nuke(row, col, radius, matrix);
- input = Console.ReadLine();
- }
- for (int i = 0; i < matrix.Count; i++)
- {
- Console.WriteLine(string.Join(" ", matrix[i]));
- }
- }
- private static void Nuke(int r, int c, int radius, List<int[]> matrix)
- {
- for (int row = r - radius; row <= r + radius; row++)
- {
- if (row >= 0 && row < matrix.Count)
- {
- if (c >= 0 && c < matrix[row].Length)
- {
- matrix[row][c] = 0;
- }
- }
- }
- for (int col = c - radius; col <= c + radius; col++)
- {
- if (r < 0 ^ r >= matrix.Count)
- {
- continue;
- }
- if (col >= 0 && col < matrix[r].Length)
- {
- matrix[r][col] = 0;
- }
- }
- for (int i = 0; i < matrix.Count; i++)
- {
- List<int> numbers = matrix[i].ToList();
- numbers.RemoveAll(a => a == 0);
- if (numbers.Count != 0)
- {
- matrix[i] = numbers.ToArray();
- }
- else
- {
- matrix.RemoveAt(i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement