Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Bomb
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- int[,] array = new int[size, size];
- for (int i = 0; i < size; i++)
- {
- int[] arrayData = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int j = 0; j < size; j++)
- {
- array[i, j] = arrayData[j];
- }
- }
- string[] inputCoords = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < inputCoords.Length; i++)
- {
- string[] coords = inputCoords[i].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- int rowCord = int.Parse(coords[0]);
- int colCord = int.Parse(coords[1]);
- int bombPower = array[rowCord, colCord];
- if (array[rowCord, colCord] > 0)
- {
- // up
- if (IsInside(array, rowCord - 1, colCord) && array[rowCord - 1, colCord] > 0)
- {
- array[rowCord - 1, colCord] -= bombPower;
- }
- //down
- if (IsInside(array, rowCord + 1, colCord) && array[rowCord + 1, colCord] > 0)
- {
- array[rowCord + 1, colCord] -= bombPower;
- }
- //left
- if (IsInside(array, rowCord, colCord + 1) && array[rowCord, colCord + 1] > 0)
- {
- array[rowCord, colCord + 1] -= bombPower;
- }
- //right
- if (IsInside(array, rowCord, colCord - 1) && array[rowCord, colCord - 1] > 0)
- {
- array[rowCord, colCord - 1] -= bombPower;
- }
- // up right diagonal
- if (IsInside(array, rowCord - 1, colCord + 1) && array[rowCord - 1, colCord + 1] > 0)
- {
- array[rowCord - 1, colCord + 1] -= bombPower;
- }
- // up left diagonal
- if (IsInside(array, rowCord - 1, colCord - 1) && array[rowCord - 1, colCord - 1] > 0)
- {
- array[rowCord - 1, colCord - 1] -= bombPower;
- }
- // down right diagonal
- if (IsInside(array, rowCord + 1, colCord + 1) && array[rowCord + 1, colCord + 1] > 0)
- {
- array[rowCord + 1, colCord + 1] -= bombPower;
- }
- // down left diagonal
- if (IsInside(array, rowCord + 1, colCord - 1) && array[rowCord + 1, colCord - 1] > 0)
- {
- array[rowCord + 1, colCord - 1] -= bombPower;
- }
- array[rowCord, colCord] = 0;
- }
- }
- int aliveCells = 0;
- int sum = 0;
- for (int i = 0; i < array.GetLength(0); i++)
- {
- for (int j = 0; j < array.GetLength(1); j++)
- {
- if (array[i, j] > 0)
- {
- sum += array[i, j];
- aliveCells++;
- }
- }
- }
- Console.WriteLine($"Alive cells: {aliveCells}");
- Console.WriteLine($"Sum: {sum}");
- for (int i = 0; i < array.GetLength(0); i++)
- {
- for (int j = 0; j < array.GetLength(1); j++)
- {
- Console.Write(array[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- private static bool IsInside(int[,] array, int row, int col)
- {
- return row >= 0 && row < array.GetLength(0) && col >= 0 && col < array.GetLength(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement