Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace TheGarden
  7. {
  8. class TheGarden
  9. {
  10. static void Main(string[] args)
  11. {
  12. int rolls = int.Parse(Console.ReadLine());
  13. var zigZag = new string[rolls][];
  14. int carrots = 0;
  15. int potatoes = 0;
  16. int lettuce = 0;
  17. int harmedVegetables = 0;
  18.  
  19.  
  20. for (int i = 0; i < rolls; i++)
  21. {
  22. string[] line = Console.ReadLine()
  23. .Split()
  24. .ToArray();
  25.  
  26. zigZag[i] = new string[line.Length];
  27.  
  28. for (int j = 0; j < line.Length; j++)
  29. {
  30. zigZag[i][j] = line[j];
  31. }
  32. }
  33.  
  34. string comand = Console.ReadLine();
  35.  
  36. while (comand != "End of Harvest")
  37. {
  38. string[] input = comand
  39. .Split()
  40. .ToArray();
  41.  
  42. if (input[0] == "Harvest")
  43. {
  44. int rollIndex = int.Parse(input[1]);
  45. int colIndex = int.Parse(input[2]);
  46.  
  47. if (rollIndex >= 0 && rollIndex < rolls && colIndex >= 0 && colIndex < zigZag[rollIndex].Length)
  48. {
  49. string type = zigZag[rollIndex][colIndex];
  50.  
  51. if (type == "C")
  52. {
  53. carrots++;
  54. }
  55. else if (type == "L")
  56. {
  57. lettuce++;
  58. }
  59. else if (type == "P")
  60. {
  61. potatoes++;
  62. }
  63.  
  64. zigZag[rollIndex][colIndex] = " ";
  65. }
  66. }
  67. else if (input[0] == "Mole")
  68. {
  69. int rollIndex = int.Parse(input[1]);
  70. int colIndex = int.Parse(input[2]);
  71.  
  72. if (rollIndex >= 0 && rollIndex < rolls && colIndex >= 0 && colIndex < zigZag[rollIndex].Length)
  73. {
  74. string direction = input[3];
  75.  
  76. switch (direction)
  77. {
  78. case "right":
  79. {
  80. for (int k = colIndex; k < zigZag[rollIndex].Length; k += 2)
  81. {
  82. if (zigZag[rollIndex][k] == "L" || zigZag[rollIndex][k] == "P" || zigZag[rollIndex][k] == "C")
  83. {
  84. harmedVegetables++;
  85. }
  86.  
  87. zigZag[rollIndex][k] = " ";
  88. }
  89.  
  90. break;
  91. }
  92. case "left":
  93. {
  94. for (int k = colIndex; k >= 0; k = -2)
  95. {
  96. if (zigZag[rollIndex][k] == "L" || zigZag[rollIndex][k] == "P" || zigZag[rollIndex][k] == "C")
  97. {
  98. harmedVegetables++;
  99. }
  100.  
  101. zigZag[rollIndex][k] = " ";
  102. }
  103.  
  104. break;
  105. }
  106. case "up":
  107. {
  108. for (int k = rollIndex; k >= 0; k = -2)
  109. {
  110. if (zigZag[k][colIndex] == "L" || zigZag[k][colIndex] == "P" || zigZag[k][colIndex] == "C")
  111. {
  112. harmedVegetables++;
  113. }
  114.  
  115. zigZag[k][colIndex] = " ";
  116. }
  117.  
  118. break;
  119. }
  120. case "down":
  121. {
  122. for (int k = rollIndex; k < rolls; k += 2)
  123. {
  124. if (zigZag[k][colIndex] == "L" || zigZag[k][colIndex] == "P" || zigZag[k][colIndex] == "C")
  125. {
  126. harmedVegetables++;
  127. }
  128.  
  129. zigZag[k][colIndex] = " ";
  130. }
  131.  
  132. break;
  133. }
  134. default:
  135. break;
  136. }
  137. }
  138. }
  139.  
  140. comand = Console.ReadLine();
  141. }
  142.  
  143. for (int i = 0; i < rolls; i++)
  144. {
  145. var sb = new StringBuilder();
  146.  
  147. for (int j = 0; j < zigZag[i].Length; j++)
  148. {
  149. sb.Append(zigZag[i][j]);
  150. sb.Append(" ");
  151. }
  152.  
  153. Console.WriteLine(sb.ToString());
  154. }
  155.  
  156. Console.WriteLine($"Carrots: {carrots}");
  157. Console.WriteLine($"Potatoes: {potatoes}");
  158. Console.WriteLine($"Lettuce: {lettuce}");
  159. Console.WriteLine($"Harmed vegetables: {harmedVegetables}");
  160. }
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement