Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- namespace TheGarden
- {
- class TheGarden
- {
- static void Main(string[] args)
- {
- int rolls = int.Parse(Console.ReadLine());
- var zigZag = new string[rolls][];
- int carrots = 0;
- int potatoes = 0;
- int lettuce = 0;
- int harmedVegetables = 0;
- for (int i = 0; i < rolls; i++)
- {
- string[] line = Console.ReadLine()
- .Split()
- .ToArray();
- zigZag[i] = new string[line.Length];
- for (int j = 0; j < line.Length; j++)
- {
- zigZag[i][j] = line[j];
- }
- }
- string comand = Console.ReadLine();
- while (comand != "End of Harvest")
- {
- string[] input = comand
- .Split()
- .ToArray();
- if (input[0] == "Harvest")
- {
- int rollIndex = int.Parse(input[1]);
- int colIndex = int.Parse(input[2]);
- if (rollIndex >= 0 && rollIndex < rolls && colIndex >= 0 && colIndex < zigZag[rollIndex].Length)
- {
- string type = zigZag[rollIndex][colIndex];
- if (type == "C")
- {
- carrots++;
- }
- else if (type == "L")
- {
- lettuce++;
- }
- else if (type == "P")
- {
- potatoes++;
- }
- zigZag[rollIndex][colIndex] = " ";
- }
- }
- else if (input[0] == "Mole")
- {
- int rollIndex = int.Parse(input[1]);
- int colIndex = int.Parse(input[2]);
- if (rollIndex >= 0 && rollIndex < rolls && colIndex >= 0 && colIndex < zigZag[rollIndex].Length)
- {
- string direction = input[3];
- switch (direction)
- {
- case "right":
- {
- for (int k = colIndex; k < zigZag[rollIndex].Length; k += 2)
- {
- if (zigZag[rollIndex][k] == "L" || zigZag[rollIndex][k] == "P" || zigZag[rollIndex][k] == "C")
- {
- harmedVegetables++;
- }
- zigZag[rollIndex][k] = " ";
- }
- break;
- }
- case "left":
- {
- for (int k = colIndex; k >= 0; k = -2)
- {
- if (zigZag[rollIndex][k] == "L" || zigZag[rollIndex][k] == "P" || zigZag[rollIndex][k] == "C")
- {
- harmedVegetables++;
- }
- zigZag[rollIndex][k] = " ";
- }
- break;
- }
- case "up":
- {
- for (int k = rollIndex; k >= 0; k = -2)
- {
- if (zigZag[k][colIndex] == "L" || zigZag[k][colIndex] == "P" || zigZag[k][colIndex] == "C")
- {
- harmedVegetables++;
- }
- zigZag[k][colIndex] = " ";
- }
- break;
- }
- case "down":
- {
- for (int k = rollIndex; k < rolls; k += 2)
- {
- if (zigZag[k][colIndex] == "L" || zigZag[k][colIndex] == "P" || zigZag[k][colIndex] == "C")
- {
- harmedVegetables++;
- }
- zigZag[k][colIndex] = " ";
- }
- break;
- }
- default:
- break;
- }
- }
- }
- comand = Console.ReadLine();
- }
- for (int i = 0; i < rolls; i++)
- {
- var sb = new StringBuilder();
- for (int j = 0; j < zigZag[i].Length; j++)
- {
- sb.Append(zigZag[i][j]);
- sb.Append(" ");
- }
- Console.WriteLine(sb.ToString());
- }
- Console.WriteLine($"Carrots: {carrots}");
- Console.WriteLine($"Potatoes: {potatoes}");
- Console.WriteLine($"Lettuce: {lettuce}");
- Console.WriteLine($"Harmed vegetables: {harmedVegetables}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement