Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ExOne
- {
- class Program
- {
- public static bool Valid(string[][] matrix, int row, int col)
- {
- if (row >= 0 && row < matrix.Length)
- {
- int current = matrix[row].Length;
- if (col >= 0 && col <= current)
- {
- return true;
- }
- }
- return false;
- }
- static void Main(string[] args)
- {
- int countRows = int.Parse(Console.ReadLine());
- string[][] array = new string[countRows][];
- for (int i = 0; i < countRows; i++)
- {
- string[] input = Console.ReadLine()
- .Split(" ");
- array[i] = new string[input.Length];
- for (int j = 0; j < input.Length; j++)
- {
- array[i][j] = input[j];
- }
- }
- int carrotsCount = 0;
- int potatoesCount = 0;
- int lettuceCount = 0;
- int harmedCount = 0;
- string command = Console.ReadLine();
- while (command.ToLower() != "end of harvest")
- {
- string[] tokens = command.
- Split(" ");
- string action = tokens[0].ToLower();
- int row = int.Parse(tokens[1]);
- int col = int.Parse(tokens[2]);
- if (action == "harvest")
- {
- if (Valid(array, row, col))
- {
- string cell = array[row][col];
- if (cell == "P")
- {
- potatoesCount++;
- array[row][col] = " ";
- }
- else if (cell == "L")
- {
- lettuceCount++;
- array[row][col] = " ";
- }
- else if (cell == "C")
- {
- carrotsCount++;
- array[row][col] = " ";
- }
- }
- }
- else if (action == "mole")
- {
- string direction = tokens[3].ToLower();
- if (Valid(array, row, col))
- {
- if (direction == "up")
- {
- for (int i = row; i >= 0; i -= 2)
- {
- if (array[i][col] != " ")
- {
- array[i][col] = " ";
- harmedCount++;
- }
- }
- }
- else if (direction == "down")
- {
- for (int i = row; i < countRows - 1; i += 2)
- {
- if (array[i][col] != " ")
- {
- array[i][col] = " ";
- harmedCount++;
- }
- }
- }
- else if (direction == "left")
- {
- for (int i = col; i >= 0; i -= 2)
- {
- if (array[row][i] != " ")
- {
- array[row][i] = " ";
- harmedCount++;
- }
- }
- }
- else if (direction == "right")
- {
- for (int i = col; i < array[row].Length; i += 2)
- {
- if (array[row][i] != " ")
- {
- array[row][i] = " ";
- harmedCount++;
- }
- }
- }
- }
- }
- command = Console.ReadLine();
- }
- foreach (var item in array)
- {
- Console.WriteLine(string.Join(" ", item));
- }
- Console.WriteLine("Carrots: {0}", carrotsCount);
- Console.WriteLine("Potatoes: {0}", potatoesCount);
- Console.WriteLine("Lettuce: {0}", lettuceCount);
- Console.WriteLine($"Harmed vegetables: {harmedCount}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement