Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _8._Bombs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int rows = int.Parse(Console.ReadLine());
- int[,] matrix = new int[rows, rows];
- for (int i = 0; i < rows; i++)
- {
- int[] values = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- for (int j = 0; j < rows; j++)
- {
- matrix[i, j] = values[j];
- }
- }
- string[] coordinates = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- for (int i = 0; i < coordinates.Count(); i++)
- {
- int[] bombCoordinates = coordinates[i]
- .Split(",", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int bombRow = bombCoordinates[0];
- int bombCol = bombCoordinates[1];
- int bombPower = matrix[bombRow, bombCol];
- matrix[bombRow, bombCol] = 0;
- //currentRow = bombRow - 1
- if (bombRow - 1 >= 0 && bombCol - 1 >= 0)
- {
- if (matrix[bombRow - 1, bombCol - 1] > 0)
- {
- matrix[bombRow - 1, bombCol - 1] -= bombPower;
- }
- }
- if (bombRow - 1 >= 0)
- {
- if (matrix[bombRow - 1, bombCol] > 0)
- {
- matrix[bombRow - 1, bombCol] -= bombPower;
- }
- }
- if (bombRow - 1 >= 0 && bombCol + 1 < rows)
- {
- if (matrix[bombRow - 1, bombCol + 1] > 0)
- {
- matrix[bombRow - 1, bombCol + 1] -= bombPower;
- }
- }
- //currentRow = bombRow
- if (bombCol - 1 >= 0)
- {
- if (matrix[bombRow, bombCol - 1] > 0)
- {
- matrix[bombRow, bombCol - 1] -= bombPower;
- }
- }
- if (bombCol + 1 < rows)
- {
- if (matrix[bombRow, bombCol + 1] > 0)
- {
- matrix[bombRow, bombCol + 1] -= bombPower;
- }
- }
- //currentRow = bombRow + 1
- if (bombRow + 1 < rows && bombCol - 1 >= 0)
- {
- if (matrix[bombRow + 1, bombCol - 1] > 0)
- {
- matrix[bombRow + 1, bombCol - 1] -= bombPower;
- }
- }
- if (bombRow + 1 < rows)
- {
- if (matrix[bombRow + 1, bombCol] > 0)
- {
- matrix[bombRow + 1, bombCol] -= bombPower;
- }
- }
- if (bombRow + 1 < rows && bombCol + 1 < rows)
- {
- if (matrix[bombRow + 1, bombCol + 1] > 0)
- {
- matrix[bombRow + 1, bombCol + 1] -= bombPower;
- }
- }
- }
- //CHECK IF THERE ARE ALIVE CELLS
- int counter = 0;
- int sum = 0;
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- if (matrix[i, j] > 0)
- {
- counter++;
- sum += matrix[i, j];
- }
- }
- }
- //OUTPUT
- Console.WriteLine($"Alive cells: {counter}");
- Console.WriteLine($"Sum: {sum}");
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- Console.Write($"{matrix[i, j]} ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement