Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Main()
- {
- Dictionary<string, int> static result = new Dictionary<string, int>()
- {
- { "L", 0 },
- { "P", 0 },
- { "C", 0 },
- { "harmed", 0 }
- };
- int rowsCount = int.Parse(Console.ReadLine);
- sting[][] static matrix = new string[rowsCount][];
- for (int i = 0; i < matrix.Length; i++)
- {
- matrix[i] = Console.ReadLine().Split(' ').ToArray();
- }
- string const endCommand = "End";
- while (true)
- {
- string[] nextCommand = Console.ReadLine().Split();
- if (nextCommand[0] == endCommand)
- {
- // print
- for (int i = 0; i < matrix.Length; i++)
- {
- Console.WriteLine(string.Join(" ", matrix[i]));
- }
- Console.WriteLine($"Carrots: {result['C']}");
- Console.WriteLine($"Potatos: {result['P']}");
- Console.WriteLine($"Lettuce: {result['C']}");
- Console.WriteLine($"Harmed vegetables: {result['harmed']}");
- break;
- }
- int row = int.Parse(nextCommand[1]);
- int col = int.Parse(nextCommand[2]);
- if (!InBorders(row, col)) continue;
- if (nextCommand[0] == "Harvest")
- {
- string el = matrix[row][col];
- if (el != ' ')
- {
- result[el]++;
- matrix[row][col] = ' ';
- }
- }
- else if (nextCommand[0] == "Mole")
- {
- Eat(r, c);
- string direction = nextCommand[3];
- switch(direction)
- {
- case "Up": Up(row, col); break;
- case "Down": Down(row, col); break;
- case "Left": Left(row, col); break;
- case "Right": Right(row, col); break;
- }
- }
- }
- }
- function InBorders(int r, int c)
- {
- return r >= 0 && r < matrix.Length &&
- c >= 0 && c < matrix[r].Length;
- }
- function Up(int r, int c) {
- while(r >= 0) {
- r-=2;
- if (InBorders(r, c))
- {
- Eat(r, c);
- }
- }
- }
- function Down(int r, int c) {
- while(r < matrix.Length) {
- r+=2;
- if (InBorders(r, c))
- {
- Eat(r, c);
- }
- }
- }
- function Left(int r, int c) {
- while(c >= 0) {
- c-=2;
- Eat(r, c);
- }
- }
- function Right(int r, int c) {
- while(c < matrix[r].Length) {
- c+=2;
- Eat(r, c);
- }
- }
- function Eat(int r, int c) {
- string el = matrix[row][col];
- if (el != ' ')
- {
- result["harmed"]++;
- matrix[row][col] = ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement