Advertisement
silvana1303

bee

Oct 24th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.48 KB | None | 0 0
  1.  
  2. using System;
  3.  
  4. namespace examPrep
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.  
  12.             char[,] matrix = new char[n, n];
  13.  
  14.             int beeRow = 0;
  15.             int beeCol = 0;
  16.             int flowers = 0;
  17.  
  18.             for (int rows = 0; rows < n; rows++)
  19.             {
  20.                 string input = Console.ReadLine();
  21.  
  22.                 ; for (int cols = 0; cols < n; cols++)
  23.                 {
  24.                     matrix[rows, cols] = input[cols];
  25.  
  26.                     if (matrix[rows, cols] == 'B')
  27.                     {
  28.                         beeRow = rows;
  29.                         beeCol = cols;
  30.                     }
  31.                 }
  32.             }
  33.  
  34.             string command = Console.ReadLine();
  35.  
  36.             while (command != "End")
  37.             {
  38.                 matrix[beeRow, beeCol] = '.';
  39.  
  40.                 if (command == "up")
  41.                 {
  42.                     beeRow--;
  43.  
  44.                     if (beeRow >= 0)
  45.                     {
  46.                         if (matrix[beeRow, beeCol] == 'f')
  47.                         {
  48.                             flowers++;
  49.                         }
  50.                         else if (matrix[beeRow, beeCol] == 'O')
  51.                         {
  52.                             matrix[beeRow, beeCol] = '.';
  53.                             beeRow--;
  54.                             if (beeRow >= 0)
  55.                             {
  56.                                 if (matrix[beeRow, beeCol] == 'f')
  57.                                 {
  58.                                     flowers++;
  59.                                 }
  60.                             }
  61.                             else
  62.                             {
  63.                                 Console.WriteLine("The bee got lost!");
  64.                                 break;
  65.                             }
  66.  
  67.                         }
  68.                     }
  69.                     else
  70.                     {
  71.                         Console.WriteLine("The bee got lost!");
  72.                         break;
  73.                     }
  74.                 }
  75.                 else if (command == "down")
  76.                 {
  77.                     beeRow++;
  78.  
  79.                     if (beeRow < n)
  80.                     {
  81.                         if (matrix[beeRow, beeCol] == 'f')
  82.                         {
  83.                             flowers++;
  84.                         }
  85.                         else if (matrix[beeRow, beeCol] == 'O')
  86.                         {
  87.                             matrix[beeRow, beeCol] = '.';
  88.                             beeRow++;
  89.                             if (beeRow < n)
  90.                             {
  91.                                 if (matrix[beeRow, beeCol] == 'f')
  92.                                 {
  93.                                     flowers++;
  94.                                 }
  95.                             }
  96.                             else
  97.                             {
  98.                                 Console.WriteLine("The bee got lost!");
  99.                                 break;
  100.                             }
  101.                         }
  102.                     }
  103.                     else
  104.                     {
  105.                         Console.WriteLine("The bee got lost!");
  106.                         break;
  107.                     }
  108.                 }
  109.                 else if (command == "left")
  110.                 {
  111.                     beeCol--;
  112.  
  113.                     if (beeCol >= 0)
  114.                     {
  115.                         if (matrix[beeRow, beeCol] == 'f')
  116.                         {
  117.                             flowers++;
  118.                         }
  119.                         else if (matrix[beeRow, beeCol] == 'O')
  120.                         {
  121.                             matrix[beeRow, beeCol] = '.';
  122.                             beeCol--;
  123.                             if (beeCol >= 0)
  124.                             {
  125.                                 if (matrix[beeRow, beeCol] == 'f')
  126.                                 {
  127.                                     flowers++;
  128.                                 }
  129.                             }
  130.                             else
  131.                             {
  132.                                 Console.WriteLine("The bee got lost!");
  133.                                 break;
  134.                             }
  135.                         }
  136.                     }
  137.                     else
  138.                     {
  139.                         Console.WriteLine("The bee got lost!");
  140.                         break;
  141.                     }
  142.                 }
  143.                 else if (command == "right")
  144.                 {
  145.                     beeCol++;
  146.  
  147.                     if (beeCol < n)
  148.                     {
  149.                         if (matrix[beeRow, beeCol] == 'f')
  150.                         {
  151.                             flowers++;
  152.                         }
  153.                         else if (matrix[beeRow, beeCol] == 'O')
  154.                         {
  155.                             matrix[beeRow, beeCol] = '.';
  156.                             beeCol++;
  157.                             if (beeCol < n)
  158.                             {
  159.                                 if (matrix[beeRow, beeCol] == 'f')
  160.                                 {
  161.                                     flowers++;
  162.                                 }
  163.                             }
  164.                             else
  165.                             {
  166.                                 Console.WriteLine("The bee got lost!");
  167.                                 break;
  168.                             }
  169.                         }
  170.                     }
  171.                     else
  172.                     {
  173.                         Console.WriteLine("The bee got lost!");
  174.                         break;
  175.                     }
  176.                 }
  177.  
  178.  
  179.                 matrix[beeRow, beeCol] = 'B';
  180.  
  181.                 command = Console.ReadLine();
  182.             }
  183.  
  184.             if (flowers >= 5)
  185.             {
  186.                 Console.WriteLine($"Great job, the bee managed to pollinate {flowers} flowers!");
  187.             }
  188.             else
  189.             {
  190.                 Console.WriteLine($"The bee couldn't pollinate the flowers, she needed {5 - flowers} flowers more");
  191.             }
  192.  
  193.             for (int rows = 0; rows < n; rows++)
  194.             {
  195.                 for (int cols = 0; cols < n; cols++)
  196.                 {
  197.                     Console.Write(matrix[rows, cols]);
  198.                 }
  199.  
  200.                 Console.WriteLine();
  201.             }
  202.  
  203.         }
  204.     }
  205. }
  206.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement