Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace TheGarden
- {
- class Program
- {
- static void Main(string[] args)
- {
- int carrotsCounter = 0;
- int potatosCounter = 0;
- int lettuceCounter = 0;
- int harmedVegetables = 0;
- int gardenRows = int.Parse(Console.ReadLine());
- char[][] arr = new char[gardenRows][];
- for (int i = 0; i < arr.Length; i++)
- {
- char[] lines = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(char.Parse)
- .ToArray();
- arr[i] = lines;
- }
- string commands = string.Empty;
- while ((commands = Console.ReadLine()) != "End of Harvest")
- {
- string[] command = commands.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- if (command[0] == "Harvest")
- {
- int row = int.Parse(command[1]);
- int col = int.Parse(command[2]);
- if (row <= arr.Length - 1 && row >= 0 && col >= 0 && col <= arr[row].Length - 1)
- {
- if (arr[row][col] == 'L')
- {
- arr[row][col] = ' ';
- lettuceCounter++;
- }
- else if (arr[row][col] == 'C')
- {
- arr[row][col] = ' ';
- carrotsCounter++;
- }
- else if (arr[row][col] == 'P')
- {
- arr[row][col] = ' ';
- potatosCounter++;
- }
- }
- }
- else if (command[0] == "Mole")
- {
- int row = int.Parse(command[1]);
- int col = int.Parse(command[2]);
- string direction = command[3];
- if (row <= arr.Length - 1 && row >= 0 && col >= 0 && col <= arr[row].Length - 1)
- {
- if (direction == "up")
- {
- for (int i = row; row >= 0; row -= 2)
- {
- if (row>=0)
- {
- if (arr[i][col] != ' ')
- {
- arr[i][col] = ' ';
- harmedVegetables++;
- }
- else
- {
- break;
- }
- }
- else
- {
- break;
- }
- }
- }
- else if (direction == "down")
- {
- for (int i = row; row <= arr.Length-1; row += 2)
- {
- if (row <= arr.Length-1)
- {
- if (arr[i][col] != ' ')
- {
- arr[i][col] = ' ';
- harmedVegetables++;
- }
- else
- {
- break;
- }
- }
- else
- {
- break;
- }
- }
- }
- else if (direction == "left")
- {
- for (int i = col; col >= 0; col -= 2)
- {
- if(col>=0)
- {
- if (arr[row][i] != ' ')
- {
- arr[row][i] = ' ';
- harmedVegetables++;
- }
- else
- {
- break;
- }
- }
- else
- {
- break;
- }
- }
- }
- else if (direction == "right")
- {
- for (int i = col; col <= arr[row].Length-1; col += 2)
- {
- if(col<=arr[row].Length-1)
- {
- if (arr[row][i] != ' ')
- {
- arr[row][i] = ' ';
- harmedVegetables++;
- }
- else
- {
- break;
- }
- }
- else
- {
- break;
- }
- }
- }
- }
- }
- }
- foreach (var row in arr)
- {
- Console.WriteLine(string.Join(" ", row));
- }
- Console.WriteLine($"Carrots: {carrotsCounter}");
- Console.WriteLine($"Potatoes: {potatosCounter}");
- Console.WriteLine($"Lettuce: {lettuceCounter}");
- Console.WriteLine($"Harmed vegetables: {harmedVegetables}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement