Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel.Design;
- using System.Linq;
- namespace TheGarden
- {
- class Program
- {
- static void Main(string[] args)
- {
- int rows = int.Parse(Console.ReadLine());
- char[][] garden = new char[rows][];
- for (int row = 0; row < garden.Length; row++)
- {
- char[] vegetables = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(char.Parse).ToArray();
- garden[row] = vegetables;
- }
- int carrotsCount = 0;
- int potatoesCount = 0;
- int lettuceCount = 0;
- int harmedVegetables = 0;
- string command = Console.ReadLine();
- while (command != "End of Harvest")
- {
- string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
- if (tokens.Length == 3)
- {
- //Harvest {row} {col}
- int row = int.Parse(tokens[1]);
- int col = int.Parse(tokens[2]);
- if (IsInside(garden, row, col))
- {
- if (garden[row][col] != ' ')
- {
- if (garden[row][col] == 'L')
- {
- lettuceCount += 1;
- }
- else if (garden[row][col] == 'P')
- {
- potatoesCount += 1;
- }
- else if (garden[row][col] == 'C')
- {
- carrotsCount += 1;
- }
- garden[row][col] = ' ';
- }
- }
- }
- else if (tokens.Length == 4)
- {
- //Mole {row} {col} {direction}
- int row = int.Parse(tokens[1]);
- int col = int.Parse(tokens[2]);
- string direction = tokens[3].ToLower();
- if (IsInside(garden, row, col))
- {
- if (garden[row][col] != ' ')
- {
- if (direction == "up")
- {
- for (int currentRow = row; currentRow >= 0; currentRow -=2)
- {
- if (IsInside(garden, currentRow, col) && garden[currentRow][col] != ' ')
- {
- garden[currentRow][col] = ' ';
- harmedVegetables += 1;
- }
- }
- }
- else if (direction == "down")
- {
- for (int currentRow = row; currentRow < garden.Length; currentRow += 2)
- {
- if (IsInside(garden, currentRow, col) && garden[currentRow][col] != ' ')
- {
- garden[currentRow][col] = ' ';
- harmedVegetables += 1;
- }
- }
- }
- else if (direction == "left")
- {
- for (int currentCol = col; currentCol >= 0; currentCol -= 2)
- {
- if (IsInside(garden, row, currentCol) && garden[row][currentCol] != ' ')
- {
- garden[row][currentCol] = ' ';
- harmedVegetables += 1;
- }
- }
- }
- else if (direction == "right")
- {
- for (int currentCol = col; currentCol < garden[row].Length; currentCol += 2)
- {
- if (IsInside(garden, row, currentCol) && garden[row][currentCol] != ' ')
- {
- garden[row][currentCol] = ' ';
- harmedVegetables += 1;
- }
- }
- }
- }
- }
- }
- command = Console.ReadLine();
- }
- foreach (char[] row in garden)
- {
- Console.WriteLine(string.Join(" ", row));
- }
- Console.WriteLine($"Carrots: {carrotsCount}");
- Console.WriteLine($"Potatoes: {potatoesCount}");
- Console.WriteLine($"Lettuce: {lettuceCount}");
- Console.WriteLine($"Harmed vegetables: {harmedVegetables}");
- }
- static bool IsInside(char[][] jaggedArray, int row, int col)
- {
- return row >= 0 && row < jaggedArray.Length && col >= 0 && col < jaggedArray[row].Length;
- }
- }
- }
Add Comment
Please, Sign In to add comment