petarkobakov

Bee

Oct 21st, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.02 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Numerics;
  4.  
  5. namespace Bee
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12.  
  13. int rows = n;
  14. int cols = n;
  15.  
  16. char[,] territory = new char[rows, cols];
  17. int pollinatedFlowers = 0;
  18. int beePositionRow = 0;
  19. int beePositionCol = 0;
  20. bool outOfTerritory = false;
  21.  
  22. for (int row = 0; row < rows; row++)
  23. {
  24. char[] currentRow = Console.ReadLine().ToCharArray();
  25.  
  26. for (int col = 0; col < cols; col++)
  27. {
  28.  
  29. territory[row, col] = currentRow[col];
  30.  
  31. if (territory[row,col] == 'B')
  32. {
  33. beePositionRow = row;
  34. beePositionCol = col;
  35. }
  36.  
  37. }
  38. }
  39.  
  40.  
  41. string command = Console.ReadLine();
  42.  
  43. while (command!="End")
  44. {
  45.  
  46. if (command == "up")
  47. {
  48. if (beePositionRow - 1 < 0 )
  49. {
  50. Console.WriteLine("The bee got lost!");
  51. territory[beePositionCol, beePositionRow] = '.';
  52. outOfTerritory = true;
  53. break;
  54. }
  55.  
  56. else
  57. {
  58. territory[beePositionRow, beePositionCol] = '.';
  59. beePositionRow -= 1;
  60.  
  61. if (territory[beePositionRow, beePositionCol] == 'f')
  62. {
  63. pollinatedFlowers++;
  64.  
  65. }
  66.  
  67. else if (territory[beePositionRow, beePositionCol] == 'O')
  68. {
  69. territory[beePositionRow, beePositionCol] = '.';
  70. beePositionRow -= 1;
  71.  
  72. if (beePositionRow < 0)
  73. {
  74. territory[beePositionCol, beePositionRow] = '.';
  75. outOfTerritory = true;
  76. break;
  77. }
  78.  
  79. else
  80. {
  81. if (territory[beePositionRow, beePositionCol] == 'f')
  82. {
  83. pollinatedFlowers++;
  84.  
  85. }
  86.  
  87. }
  88. }
  89.  
  90. territory[beePositionRow, beePositionCol] = 'B';
  91. }
  92. }
  93.  
  94. else if (command == "down")
  95. {
  96. if (beePositionRow + 1 > rows-1)
  97. {
  98. Console.WriteLine("The bee got lost!");
  99. territory[beePositionCol, beePositionRow] = '.';
  100. outOfTerritory = true;
  101. break;
  102. }
  103.  
  104. else
  105. {
  106. territory[beePositionRow, beePositionCol] = '.';
  107. beePositionRow += 1;
  108.  
  109. if (territory[beePositionRow, beePositionCol] == 'f')
  110. {
  111. pollinatedFlowers++;
  112.  
  113. }
  114.  
  115. else if (territory[beePositionRow, beePositionCol] == 'O')
  116. {
  117. territory[beePositionRow, beePositionCol] = '.';
  118. beePositionRow += 1;
  119.  
  120. if (beePositionRow > rows-1)
  121. {
  122. territory[beePositionCol, beePositionRow] = '.';
  123. outOfTerritory = true;
  124. break;
  125. }
  126.  
  127. else
  128. {
  129. if (territory[beePositionRow, beePositionCol] == 'f')
  130. {
  131. pollinatedFlowers++;
  132.  
  133. }
  134. }
  135. }
  136.  
  137. territory[beePositionRow, beePositionCol] = 'B';
  138. }
  139.  
  140. }
  141.  
  142. else if (command == "left")
  143. {
  144. if (beePositionCol - 1 < 0)
  145. {
  146. Console.WriteLine("The bee got lost!");
  147. territory[beePositionCol, beePositionRow] = '.';
  148. outOfTerritory = true;
  149. break;
  150. }
  151.  
  152. else
  153. {
  154. territory[beePositionRow, beePositionCol] = '.';
  155. beePositionCol -= 1;
  156.  
  157. if (territory[beePositionRow, beePositionCol] == 'f')
  158. {
  159. pollinatedFlowers++;
  160.  
  161. }
  162.  
  163. else if (territory[beePositionRow, beePositionCol] == 'O')
  164. {
  165. territory[beePositionRow, beePositionCol] = '.';
  166. beePositionCol -= 1;
  167.  
  168. if (beePositionCol < 0)
  169. {
  170. territory[beePositionCol, beePositionRow] = '.';
  171. outOfTerritory = true;
  172. break;
  173. }
  174.  
  175. else
  176. {
  177. if (territory[beePositionRow, beePositionCol] == 'f')
  178. {
  179. pollinatedFlowers++;
  180.  
  181. }
  182. }
  183. }
  184.  
  185. territory[beePositionRow, beePositionCol] = 'B';
  186. }
  187.  
  188. }
  189.  
  190. else if (command == "right")
  191. {
  192. if (beePositionCol + 1 > cols-1)
  193. {
  194. Console.WriteLine("The bee got lost!");
  195. territory[beePositionCol, beePositionRow] = '.';
  196. outOfTerritory = true;
  197. break;
  198. }
  199.  
  200. else
  201. {
  202. territory[beePositionRow, beePositionCol] = '.';
  203. beePositionCol += 1;
  204.  
  205. if (territory[beePositionRow, beePositionCol] == 'f')
  206. {
  207. pollinatedFlowers++;
  208.  
  209. }
  210.  
  211. else if (territory[beePositionRow, beePositionCol] == 'O')
  212. {
  213. territory[beePositionRow, beePositionCol] = '.';
  214. beePositionCol += 1;
  215.  
  216. if (beePositionCol > cols-1)
  217. {
  218. territory[beePositionCol, beePositionRow] = '.';
  219. outOfTerritory = true;
  220. break;
  221. }
  222.  
  223. else
  224. {
  225. if (territory[beePositionRow, beePositionCol] == 'f')
  226. {
  227. pollinatedFlowers++;
  228.  
  229. }
  230. }
  231. }
  232.  
  233. territory[beePositionRow, beePositionCol] = 'B';
  234. }
  235. }
  236.  
  237. if (outOfTerritory)
  238. {
  239.  
  240. break;
  241. }
  242.  
  243. command = Console.ReadLine();
  244. }
  245.  
  246. int pollinetedFlowersNeeded = 5 - pollinatedFlowers;
  247.  
  248. if (pollinatedFlowers<5)
  249. {
  250. Console.WriteLine($"The bee couldn't pollinate the flowers, she needed {pollinetedFlowersNeeded} flowers more");
  251. }
  252. else
  253. {
  254. Console.WriteLine($"Great job, the bee managed to pollinate {pollinatedFlowers} flowers!");
  255. }
  256.  
  257.  
  258. for (int row = 0; row < rows; row++)
  259. {
  260. for (int col = 0; col < cols; col++)
  261. {
  262. Console.Write(territory[row,col]);
  263. }
  264.  
  265. Console.WriteLine();
  266. }
  267. }
  268. }
  269. }
  270.  
Advertisement
Add Comment
Please, Sign In to add comment