Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace P01The_Garden
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[][] matrix = new char[n][];
- int harmed = 0;
- int carrots = 0;
- int potatoes = 0;
- int l = 0;
- for (int i = 0; i < n; i++)
- {
- char[] input = Console.ReadLine().Split().Select(char.Parse).ToArray();
- matrix[i] = input;
- }
- while (true)
- {
- string end = Console.ReadLine();
- if (end == "End of Harvest")
- {
- break;
- }
- string[] input = end.Split();
- int row = int.Parse(input[1]);
- int col = int.Parse(input[2]);
- if (input[0] == "Harvest")
- {
- if (IsInside(row, col, n, matrix) == true)
- {
- if (matrix[row][col] == 'L' || matrix[row][col] == 'P' || matrix[row][col] == 'C')
- {
- if (matrix[row][col] == 'C')
- {
- carrots++;
- }
- if (matrix[row][col] == 'P')
- {
- potatoes++;
- }
- if (matrix[row][col] == 'L')
- {
- l++;
- }
- matrix[row][col] = ' ';
- }
- }
- }
- else if (input[0] == "Mole")
- {
- if (matrix[row][col] == 'L' || matrix[row][col] == 'P' || matrix[row][col] == 'C')
- {
- matrix[row][col] = ' ';
- harmed++;
- }
- while (true)
- {
- if (input[3] == "up")
- {
- if (datiebamaikata(row - 2, col, n, matrix, harmed) == false)
- {
- break;
- }
- if (mnsumprost(row - 2, col, matrix))
- {
- harmed++;
- }
- Mole(row - 2, col, n, matrix, harmed);
- row -= 2;
- }
- if (input[3] == "down")
- {
- if (datiebamaikata(row + 2, col, n, matrix, harmed) == false)
- {
- break;
- }
- if (mnsumprost(row + 2, col, matrix))
- {
- harmed++;
- }
- Mole(row + 2, col, n, matrix, harmed);
- row += 2;
- }
- if (input[3] == "left")
- {
- if (datiebamaikata(row, col - 2, n, matrix, harmed) == false)
- {
- break;
- }
- if (mnsumprost(row, col - 2, matrix))
- {
- harmed++;
- }
- Mole(row, col - 2, n, matrix, harmed);
- col -= 2;
- }
- if (input[3] == "right")
- {
- if (datiebamaikata(row, col + 2, n, matrix, harmed) == false)
- {
- break;
- }
- if (mnsumprost(row, col + 2,matrix))
- {
- harmed++;
- }
- Mole(row, col + 2, n, matrix, harmed);
- col += 2;
- }
- }
- }
- }
- foreach (var item in matrix)
- {
- Console.WriteLine(string.Join(" ", item));
- }
- Console.WriteLine($"Carrots: {carrots}");
- Console.WriteLine($"Potatoes: {potatoes}");
- Console.WriteLine($"Lettuce: {l}");
- Console.WriteLine($"Harmed vegetables: {harmed}");
- }
- public static void Mole(int row, int col, int n, char[][] matrix,int harmed)
- {
- if(IsInside(row, col, n, matrix))
- {
- if (matrix[row][col] == 'L' || matrix[row][col] == 'P' || matrix[row][col] == 'C')
- {
- matrix[row][col] = ' ';
- }
- }
- }
- public static bool datiebamaikata(int row, int col, int n, char[][] matrix, int harmed)
- {
- if (IsInside(row, col, n, matrix))
- {
- return true;
- }
- return false;
- }
- public static bool IsInside(int row, int col, int n, char[][] matrix)
- {
- if (row < 0 || row >= n || col < 0 || col >= matrix[row].Length)
- {
- return false;
- }
- return true;
- }
- public static bool mnsumprost(int row, int col, char[][] matrix)
- {
- if (matrix[row][col] == ' ')
- {
- return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement