Професионална програма
Loading...
RebeccaBoeva avatar RebeccaBoeva 0 Точки

zdravei otnovo :D

sujalqvam izpratila sum napulno greshen kod....

TOVA TUK E VERNIQ ----->

using System;
using System.Collections.Generic;

namespace The_Garden
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int rowsCount = int.Parse(Console.ReadLine());

            string[][] array = new string[rowsCount][];

            for (int i = 0; i < rowsCount; i++)
            {
                string[] inputData = Console.ReadLine()
                        .Split(" ", StringSplitOptions.RemoveEmptyEntries);
                array[i] = new string[inputData.Length];

                for (int j = 0; j < inputData.Length; j++)
                {
                    array[i][j] = inputData[j];
                }
            }

            string[] command = Console.ReadLine()
                                .Split();

            int harmedCount = 0;
            int carrots = 0;
            int potatoes = 0;
            int lettuce = 0;

            while (command[0] != "End" && command[1] != "of" && command[2] != "Harvest")
            {
                if (command[0] == "Harvest")
                {
                    int firstIndex = int.Parse(command[1]);
                    int secIndex = int.Parse(command[2]);
                    for (int i = 0; i < array.Length; i++)
                    {
                        for (int j = 0; j < array[i].Length; j++)
                        {
                            if (i == firstIndex && j == secIndex)
                            {
                                if (array[i][j] == "C")
                                {
                                    carrots++;
                                }
                                else if (array[i][j] == "P")
                                {
                                    potatoes++;
                                }
                                else if (array[i][j] == "L")
                                {
                                    lettuce++;
                                }
                                array[i][j] = " ";
                            }
                        }
                    }
                }

                else if (command[0] == "Mole")
                {
                    int firstIndex = int.Parse(command[1]);
                    int secIndex = int.Parse(command[2]);
                    string side = command[3];

                    for (int i = 0; i < array.Length; i++)
                    {
                        for (int j = 0; j < array[i].Length; j++)
                        {
                            if (i == firstIndex && j == secIndex && array[i][j] != " ")
                            {
                                if (side == "up")
                                {
                                    for (int k = firstIndex; k >= 0; k -= 2)
                                    {
                                        if (array[k][secIndex] != " ")
                                        {
                                            array[k][secIndex] = " ";
                                            harmedCount++;
                                        }
                                    }
                                }

                                else if (side == "down")
                                {
                                    for (int k = firstIndex; k < array.Length; k += 2)
                                    {
                                        if (array[k][secIndex] != " ")
                                        {
                                            array[k][secIndex] = " ";
                                            harmedCount++;
                                        }
                                    }
                                }

                                else if (side == "right")
                                {
                                    for (int k = secIndex; k < array[i].Length; k += 2)
                                    {
                                        if (array[firstIndex][k] != " ")
                                        {
                                            array[firstIndex][k] = " ";
                                            harmedCount++;
                                        }
                                    }
                                }

                                else if (side == "left")
                                {
                                    for (int k = secIndex; k >= 0; k -= 2)
                                    {
                                        if (array[firstIndex][k] != " ")
                                        {
                                            array[firstIndex][k] = " ";
                                            harmedCount++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                command = Console.ReadLine()
                                .Split();

            }

            for (int i = 0; i < array.Length; i++)
            {
                for (int j = 0; j < array[i].Length; j++)
                {
                    Console.Write(array[i][j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine($"Carrots: {carrots}");
            Console.WriteLine($"Potatoes: {potatoes}");
            Console.WriteLine($"Lettuce: {lettuce}");
            Console.WriteLine($"Harmed vegetables: {harmedCount}");
        }
    }
}

-1