Exemple #1
0
        static void Main()
        {
            InitializeMatrix(out var matrix);
            Targetdetails target = null;

            while (TakeInput(ref target))
            {
                Strike(ref matrix, ref target);
            }

            PrintMatrix(ref matrix);
        }
Exemple #2
0
        static bool TakeInput(ref Targetdetails target)
        {
            var input = Console.ReadLine();

            if (input == "Nuke it from orbit")
            {
                return(false);
            }

            var targetAndRadius = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                  .Select(int.Parse).ToArray();

            int targetRow    = targetAndRadius[0];
            int targetCol    = targetAndRadius[1];
            int targetRadius = targetAndRadius[2];

            target = new Targetdetails(targetRow, targetCol, targetRadius);
            return(true);
        }
Exemple #3
0
        static void Strike(ref List <List <long> > matrix, ref Targetdetails target)
        {
            for (int row = target.Row - target.Radius; row <= target.Row + target.Radius; row++)
            {
                if (row < 0 || row >= matrix.Count)
                {
                    continue;
                }

                if (row == target.Row)
                {
                    for (int col = target.Col + target.Radius; col >= target.Col - target.Radius; col--)
                    {
                        if (col < 0 || col >= matrix[row].Count)
                        {
                            continue;
                        }
                        matrix[row].RemoveAt(col);
                    }
                }
                else
                {
                    if (target.Col < 0 || target.Col >= matrix[row].Count)
                    {
                        continue;
                    }
                    matrix[row].RemoveAt(target.Col);
                }
            }

            for (int row = 0; row < matrix.Count; row++)
            {
                if (matrix[row].Count == 0)
                {
                    matrix.RemoveAt(row);
                    row--;
                }
            }
        }