Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Bombs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int[,] matrix = new int[n, n];
- for (int row = 0; row < n; row++)
- {
- int[] data = Console.ReadLine().Split().Select(int.Parse).ToArray();
- for (int col = 0; col < n; col++)
- {
- matrix[row, col] = data[col];
- }
- }
- string[] command = Console.ReadLine().Split();
- string[] first = command[0].Split(",");
- int firsBombRow = int.Parse(first[0]);
- int firstBombCol = int.Parse(first[1]);
- string[] second = command[1].Split(",");
- int secondBombRow = int.Parse(second[0]);
- int secondBombCol = int.Parse(second[1]);
- string[] third = command[2].Split(",");
- int thirdBombRow = int.Parse(third[0]);
- int thirdBombCol = int.Parse(third[1]);
- List<int[]> bombs = new List<int[]>();
- bombs.Add(new int[] { firsBombRow, firstBombCol });
- bombs.Add(new int[] { secondBombRow, secondBombCol });
- bombs.Add(new int[] { thirdBombRow, thirdBombCol });
- for (int i = 0; i < bombs.Count; i++)
- {
- int rowBomb = bombs[i][0];
- int colBomb = bombs[i][1];
- if (IsValidCellCell(rowBomb - 1, colBomb - 1, n) && matrix[rowBomb - 1, colBomb - 1] >= 0)
- {
- matrix[rowBomb - 1, colBomb - 1] -= matrix[rowBomb, colBomb];
- }
- if (IsValidCellCell(rowBomb - 1, colBomb + 1, n) && matrix[rowBomb - 1, colBomb + 1] >= 0)
- {
- matrix[rowBomb - 1, colBomb + 1] -= matrix[rowBomb, colBomb];
- }
- if (IsValidCellCell(rowBomb - 1, colBomb, n) && matrix[rowBomb - 1, colBomb] >= 0)
- {
- matrix[rowBomb - 1, colBomb] -= matrix[rowBomb, colBomb];
- }
- if (IsValidCellCell(rowBomb + 1, colBomb - 1, n) && matrix[rowBomb + 1, colBomb - 1] >= 0)
- {
- matrix[rowBomb + 1, colBomb - 1] -= matrix[rowBomb, colBomb];
- }
- if (IsValidCellCell(rowBomb + 1, colBomb + 1, n) && matrix[rowBomb + 1, colBomb + 1] >= 0)
- {
- matrix[rowBomb + 1, colBomb + 1] -= matrix[rowBomb, colBomb];
- }
- if (IsValidCellCell(rowBomb + 1, colBomb, n) && matrix[rowBomb + 1, colBomb] >= 0)
- {
- matrix[rowBomb + 1, colBomb] -= matrix[rowBomb, colBomb];
- }
- if (IsValidCellCell(rowBomb, colBomb - 1, n) && matrix[rowBomb, colBomb - 1] >= 0)
- {
- matrix[rowBomb, colBomb - 1] -= matrix[rowBomb, colBomb];
- }
- if (IsValidCellCell(rowBomb, colBomb + 1, n) && matrix[rowBomb, colBomb + 1] >= 0)
- {
- matrix[rowBomb, colBomb + 1] -= matrix[rowBomb, colBomb];
- }
- }
- matrix[firsBombRow, firstBombCol] = 0;
- matrix[secondBombRow, secondBombCol] = 0;
- matrix[thirdBombRow, thirdBombCol] = 0;
- int aliveCells = 0;
- int sum = 0;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- if (matrix[row, col] > 0)
- {
- aliveCells++;
- sum += matrix[row, col];
- }
- }
- }
- Console.WriteLine($"Alive cells: {aliveCells}");
- Console.WriteLine($"Sum: {sum}");
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- if (col != n)
- {
- Console.Write($"{matrix[row, col]} ");
- }
- else
- {
- Console.Write($"{matrix[row, col]}");
- }
- }
- Console.WriteLine();
- }
- }
- static bool IsValidCellCell(int row, int col, int n)
- {
- return row >= 0 && row < n && col >= 0 && col < n;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement