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