Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ConsoleApp5
- {
- class Program
- {
- static void Main(string[] args)
- {
- int inputRowsColums = int.Parse(Console.ReadLine());
- int rows = inputRowsColums;
- int colums = rows;
- int[,] matrix = new int[rows, colums];
- //inputMatrix
- for (int row = 0; row < rows; row++)
- {
- int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
- for (int col = 0; col < colums; col++)
- {
- matrix[row, col] = input[col];
- }
- }
- string[] bombs = Console.ReadLine().Split().ToArray();
- for (int i = 0; i < bombs.Length; i++)
- {
- int[] rowColBomb = bombs[i].Split(",").Select(int.Parse).ToArray();
- int rowBomb = rowColBomb[0];
- int colBomb = rowColBomb[1];
- int bombPower = matrix[rowBomb, colBomb];
- if (matrix[rowBomb, colBomb] <= 0)
- {
- continue;
- }
- for (int row = Math.Max(rowBomb - 1, 0); row <= Math.Min(rowBomb + 1, rows-1); row++)
- {
- for (int col = Math.Max(colBomb - 1, 0); col <= Math.Min(colBomb + 1, colums-1); col++)
- {
- if (matrix[row, col] <= 0)
- {
- continue;
- }
- matrix[row, col] -= bombPower;
- }
- }
- matrix[rowBomb, colBomb] = 0;
- }
- //checkActiveCells and calculate sum
- int active = 0;
- int sum = 0;
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < colums; col++)
- {
- if (matrix[row, col] > 0)
- {
- active++;
- sum += matrix[row, col];
- }
- }
- }
- Console.WriteLine($"Alive cells: {active}");
- Console.WriteLine($"Sum: {sum}");
- //printMatrix
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < colums-1; col++)
- {
- Console.Write(matrix[row, col] + " ");
- }
- Console.Write(matrix[row, colums-1]);
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement