Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace examPrep
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[,] matrix = new char[n, n];
- int beeRow = 0;
- int beeCol = 0;
- int flowers = 0;
- for (int rows = 0; rows < n; rows++)
- {
- string input = Console.ReadLine();
- ; for (int cols = 0; cols < n; cols++)
- {
- matrix[rows, cols] = input[cols];
- if (matrix[rows, cols] == 'B')
- {
- beeRow = rows;
- beeCol = cols;
- }
- }
- }
- string command = Console.ReadLine();
- while (command != "End")
- {
- matrix[beeRow, beeCol] = '.';
- if (command == "up")
- {
- beeRow--;
- if (beeRow >= 0)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- else if (matrix[beeRow, beeCol] == 'O')
- {
- matrix[beeRow, beeCol] = '.';
- beeRow--;
- if (beeRow >= 0)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- else if (command == "down")
- {
- beeRow++;
- if (beeRow < n)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- else if (matrix[beeRow, beeCol] == 'O')
- {
- matrix[beeRow, beeCol] = '.';
- beeRow++;
- if (beeRow < n)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- else if (command == "left")
- {
- beeCol--;
- if (beeCol >= 0)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- else if (matrix[beeRow, beeCol] == 'O')
- {
- matrix[beeRow, beeCol] = '.';
- beeCol--;
- if (beeCol >= 0)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- else if (command == "right")
- {
- beeCol++;
- if (beeCol < n)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- else if (matrix[beeRow, beeCol] == 'O')
- {
- matrix[beeRow, beeCol] = '.';
- beeCol++;
- if (beeCol < n)
- {
- if (matrix[beeRow, beeCol] == 'f')
- {
- flowers++;
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- matrix[beeRow, beeCol] = 'B';
- command = Console.ReadLine();
- }
- if (flowers >= 5)
- {
- Console.WriteLine($"Great job, the bee managed to pollinate {flowers} flowers!");
- }
- else
- {
- Console.WriteLine($"The bee couldn't pollinate the flowers, she needed {5 - flowers} flowers more");
- }
- for (int rows = 0; rows < n; rows++)
- {
- for (int cols = 0; cols < n; cols++)
- {
- Console.Write(matrix[rows, cols]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement