Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Bee
- {
- 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 i = 0; i < n; i++)
- {
- string input = Console.ReadLine();
- for (int j = 0; j < n; j++)
- {
- matrix[i, j] = input[j];
- if (matrix[i, j] == 'B')
- {
- beerow = i;
- beecol = j;
- }
- }
- }
- string command = Console.ReadLine();
- while (command != "End")
- {
- matrix[beerow, beecol] = '.';
- if (command == "right")
- {
- beecol++;
- if (beecol < n)
- {
- if (matrix[beerow, beecol] == 'f')
- {
- flowers++;
- }
- else if (matrix[beerow, beecol] == 'O')
- {
- matrix[beerow, beecol] = '.';
- beecol++;
- if (matrix[beerow, beecol] == 'f')
- {
- flowers++;
- }
- }
- }
- 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 (matrix[beerow, beecol] == 'f')
- {
- flowers++;
- }
- }
- }
- 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 (matrix[beerow, beecol] == 'f')
- {
- flowers++;
- }
- }
- }
- else
- {
- Console.WriteLine("The bee got lost!");
- break;
- }
- }
- else if (command == "up")
- {
- beerow--;
- if (beerow >= 0)
- {
- if (matrix[beerow, beecol] == 'f')
- {
- flowers++;
- }
- else if (matrix[beerow, beecol] == 'O')
- {
- matrix[beerow, beecol] = '.';
- beerow--;
- if (matrix[beerow, beecol] == 'f')
- {
- flowers++;
- }
- }
- }
- 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 i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write($"{matrix[i, j]}");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement