8. *Bombs - Judge - 50.
здравейте,какво трябва да се промени в логиката на задачата от тема - матрици?
using System;
using System.Collections.Generic;
using System.Linq;
namespace MatrixBombs
{
    class Program
    {
        public static object Matrix { get; private set; }
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());
int[,] matrix = ReadMatrix(input, input);
            string[] positionBomb = Console.ReadLine().Split().ToArray();
            List<int[]> negativPosition = new List<int[]>();
            for (int i = 0; i < positionBomb.Length; i++)
            {
                int[] Bomb = positionBomb[i].Split(',').Select(int.Parse).ToArray();
                negativPosition.Add(Bomb);
            }
            while (negativPosition.Count > 0)
            {
                int rowBomb = negativPosition[0][0];
                int colBomb = negativPosition[0][1];
                negativPosition.RemoveAt(0);
                if(matrix[rowBomb,colBomb] <= 0)
                {
                    continue;
                }
                int count = 0;
                for (int i = 0; i < matrix.GetLength(0); i++)
                {
                    for (int j = 0; j < matrix.GetLength(1); j++)
                    {
                        if (j == colBomb || j == colBomb + 1 || j == colBomb - 1)
                        {
                            if (i == rowBomb + 1 || i == rowBomb - 1 || i == rowBomb)
                            {
                                for (int c = 0; c < negativPosition.Count; c++)
                                {
                                    if (negativPosition[c][0] == i && negativPosition[c][1] == j)
                                    {
                                        int[] reversPosition = negativPosition[count].ToArray();
                                        negativPosition[count] = negativPosition[c].ToArray();
                                        negativPosition[c] = reversPosition.ToArray();
                                        count++;
}
                                }
                                if (matrix[i, j] > 0 && matrix[i, j] != matrix[rowBomb, colBomb])
                                {
                                    matrix[i, j] -= matrix[rowBomb, colBomb];
}
                            }
                        }
}
}
                matrix[rowBomb, colBomb] = 0;
            }
            int sum = 0;
            int count1 = 0;
            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    if (matrix[i, j] > 0)
                    {
                        count1++;
                        sum += matrix[i, j];
                    }
                }
            }
            Console.WriteLine($"Alive cells: {count1}");
            Console.WriteLine("Sum: " + sum);
            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    if (j == matrix.GetLength(1) - 1)
                    {
                        Console.Write(matrix[i, j]);
                    }
                    else
                    {
                        Console.Write(matrix[i, j] + " ");
                    }
                }
                Console.WriteLine();
            }
        }
        static int[,] ReadMatrix(int row, int col)
        {
            int[,] matrix = new int[row, col];
            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    matrix[i, j] = array[j];
                }
            }
            return matrix;
        }
       
    }
}
може да се усложни задачата и ако периметъра на взривената бомба обхваща други бомби ,да се взривят първо те последователно по ред , колона в матрицата и чак след това бомбата по индекс от подавания масив.Тогава може да се използва лист ,или стак ,или опашка за правилно координиране на детонациите
using System;
using System.Collections.Generic;
using System.Linq;
namespace MatrixBombs
{
class Program
{
public static object Matrix { get; private set; }
static void Main(string[] args)
{
int input = int.Parse(Console.ReadLine());
int[,] matrix = ReadMatrix(input, input);
string[] positionBomb = Console.ReadLine().Split().ToArray();
List<int[]> negativPosition = new List<int[]>();
for (int i = 0; i < positionBomb.Length; i++)
{
int[] Bomb = positionBomb[i].Split(',').Select(int.Parse).ToArray();
negativPosition.Add(Bomb);
}
while (negativPosition.Count > 0)
{
int rowBomb = negativPosition[0][0];
int colBomb = negativPosition[0][1];
negativPosition.RemoveAt(0);
if (rowBomb < 0 || rowBomb >= matrix.GetLength(0) || colBomb < 0 || colBomb >= matrix.GetLength(1))
{
continue;
}
int o = matrix[rowBomb, colBomb];
int count = 0;
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
if (j == colBomb || j == colBomb + 1 || j == colBomb - 1)
{
if (i == rowBomb + 1 || i == rowBomb - 1 || i == rowBomb)
{
for (int c = 0; c < negativPosition.Count; c++)
{
if (negativPosition[c][0] == i && negativPosition[c][1] == j)
{
int[] reversPosition = negativPosition[count].ToArray();
negativPosition[count] = negativPosition[c].ToArray();
negativPosition.Insert(count + 1, reversPosition);
negativPosition.RemoveAt(c);
count++;
}
}
if (matrix[i, j] > 0 && o > 0)
{
matrix[i, j] -= o;
}
}
}
}
}
}
int sum = 0;
int count1 = 0;
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
if (matrix[i, j] > 0)
{
count1++;
sum += matrix[i, j];
}
}
}
Console.WriteLine($"Alive cells: {count1}");
Console.WriteLine("Sum: " + sum);
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
if (j == matrix.GetLength(1) - 1)
{
Console.Write(matrix[i, j]);
}
else
{
Console.Write(matrix[i, j] + " ");
}
}
Console.WriteLine();
}
}
static int[,] ReadMatrix(int row, int col)
{
int[,] matrix = new int[row, col];
for (int i = 0; i < matrix.GetLength(0); i++)
{
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int j = 0; j < matrix.GetLength(1); j++)
{
matrix[i, j] = array[j];
}
}
return matrix;
}
}
}