Advertisement
svetlyoek

Untitled

Jun 16th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace TheGarden
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int carrotsCounter = 0;
  11. int potatosCounter = 0;
  12. int lettuceCounter = 0;
  13. int harmedVegetables = 0;
  14.  
  15. int gardenRows = int.Parse(Console.ReadLine());
  16. char[][] arr = new char[gardenRows][];
  17.  
  18. for (int i = 0; i < arr.Length; i++)
  19. {
  20. char[] lines = Console.ReadLine()
  21. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  22. .Select(char.Parse)
  23. .ToArray();
  24.  
  25. arr[i] = lines;
  26. }
  27.  
  28. string commands = string.Empty;
  29.  
  30. while ((commands = Console.ReadLine()) != "End of Harvest")
  31. {
  32. string[] command = commands.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  33.  
  34. if (command[0] == "Harvest")
  35. {
  36. int row = int.Parse(command[1]);
  37. int col = int.Parse(command[2]);
  38.  
  39. if (row <= arr.Length - 1 && row >= 0 && col >= 0 && col <= arr[row].Length - 1)
  40. {
  41.  
  42. if (arr[row][col] == 'L')
  43. {
  44. arr[row][col] = ' ';
  45. lettuceCounter++;
  46. }
  47. else if (arr[row][col] == 'C')
  48. {
  49. arr[row][col] = ' ';
  50. carrotsCounter++;
  51. }
  52.  
  53. else if (arr[row][col] == 'P')
  54. {
  55. arr[row][col] = ' ';
  56. potatosCounter++;
  57. }
  58. }
  59. }
  60.  
  61.  
  62. else if (command[0] == "Mole")
  63. {
  64. int row = int.Parse(command[1]);
  65. int col = int.Parse(command[2]);
  66. string direction = command[3];
  67. if (row <= arr.Length - 1 && row >= 0 && col >= 0 && col <= arr[row].Length - 1)
  68. {
  69. if (direction == "up")
  70. {
  71.  
  72. for (int i = row; row >= 0; row -= 2)
  73. {
  74. if (row>=0)
  75. {
  76. if (arr[i][col] != ' ')
  77. {
  78. arr[i][col] = ' ';
  79. harmedVegetables++;
  80. }
  81. else
  82. {
  83. break;
  84. }
  85. }
  86. else
  87. {
  88. break;
  89. }
  90.  
  91.  
  92. }
  93. }
  94.  
  95. else if (direction == "down")
  96. {
  97.  
  98. for (int i = row; row <= arr.Length-1; row += 2)
  99. {
  100. if (row <= arr.Length-1)
  101. {
  102. if (arr[i][col] != ' ')
  103. {
  104. arr[i][col] = ' ';
  105. harmedVegetables++;
  106. }
  107. else
  108. {
  109. break;
  110. }
  111.  
  112. }
  113. else
  114. {
  115. break;
  116. }
  117.  
  118.  
  119. }
  120. }
  121. else if (direction == "left")
  122. {
  123.  
  124. for (int i = col; col >= 0; col -= 2)
  125. {
  126. if(col>=0)
  127. {
  128. if (arr[row][i] != ' ')
  129. {
  130. arr[row][i] = ' ';
  131. harmedVegetables++;
  132. }
  133. else
  134. {
  135. break;
  136. }
  137.  
  138. }
  139. else
  140. {
  141. break;
  142. }
  143.  
  144.  
  145. }
  146. }
  147.  
  148. else if (direction == "right")
  149. {
  150.  
  151.  
  152. for (int i = col; col <= arr[row].Length-1; col += 2)
  153. {
  154. if(col<=arr[row].Length-1)
  155. {
  156. if (arr[row][i] != ' ')
  157. {
  158. arr[row][i] = ' ';
  159. harmedVegetables++;
  160. }
  161. else
  162. {
  163. break;
  164. }
  165.  
  166. }
  167. else
  168. {
  169. break;
  170. }
  171.  
  172.  
  173. }
  174. }
  175. }
  176. }
  177. }
  178.  
  179. foreach (var row in arr)
  180. {
  181. Console.WriteLine(string.Join(" ", row));
  182. }
  183.  
  184. Console.WriteLine($"Carrots: {carrotsCounter}");
  185. Console.WriteLine($"Potatoes: {potatosCounter}");
  186. Console.WriteLine($"Lettuce: {lettuceCounter}");
  187. Console.WriteLine($"Harmed vegetables: {harmedVegetables}");
  188. }
  189.  
  190. }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement