Advertisement
Guest User

Untitled

a guest
Jan 9th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ladybugs10
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int fieldSize = int.Parse(Console.ReadLine());
  11.  
  12. int[] ladybugIndexes = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.  
  14. int[] result = new int[fieldSize];
  15.  
  16. int counter = 0;
  17.  
  18. for (int i = 0; i < result.Length; i++)
  19. {
  20. if (counter == ladybugIndexes.Length)
  21. {
  22. break;
  23. }
  24.  
  25. if (ladybugIndexes[counter] < 0)
  26. {
  27. counter++;
  28. i = -1;
  29. continue;
  30. }
  31.  
  32. if (ladybugIndexes[counter] == i)
  33. {
  34. counter++;
  35. result[i] = 1;
  36. }
  37. }
  38.  
  39. string input = Console.ReadLine();
  40.  
  41. bool isWrongDirection = false;
  42.  
  43. while (input != "end")
  44. {
  45. string[] command = input.Split(' ');
  46.  
  47. int index = int.Parse(command[0]);
  48. string direction = command[1];
  49. int length = int.Parse(command[2]);
  50.  
  51. for (int i = 0; i < result.Length; i++)
  52. {
  53. if (index == i && result[i] == 1)
  54. {
  55. int ladybug = i;
  56.  
  57. switch (direction)
  58. {
  59. case "right":
  60. if (length < 0)
  61. {
  62. direction = "left";
  63. length *= -1;
  64. ladybug -= length;
  65. break;
  66. }
  67.  
  68. ladybug += length;
  69. break;
  70. case "left":
  71. if (length < 0)
  72. {
  73. direction = "right";
  74. length *= -1;
  75. ladybug += length;
  76. break;
  77. }
  78.  
  79. ladybug -= length;
  80. break;
  81. default: isWrongDirection = true; break;
  82. }
  83.  
  84. if (isWrongDirection)
  85. {
  86. isWrongDirection = false;
  87. break;
  88. }
  89.  
  90. if (ladybug >= result.Length || ladybug < 0)
  91. {
  92. result[index] = 0;
  93.  
  94. if (result.Length == 0)
  95. {
  96. continue;
  97. }
  98.  
  99. continue;
  100. }
  101.  
  102. if (length == 0)
  103. {
  104. continue;
  105. }
  106.  
  107. int iterator = i;
  108.  
  109. if (direction == "right")
  110. {
  111. while (true)
  112. {
  113. iterator += length;
  114.  
  115. if (iterator >= result.Length)
  116. {
  117. break;
  118. }
  119.  
  120. if (ladybug == iterator && result[iterator] == 1 && iterator < result.Length)
  121. {
  122. ladybug += length;
  123. }
  124. else
  125. {
  126. break;
  127. }
  128. }
  129. }
  130. else if (direction == "left")
  131. {
  132. while (true)
  133. {
  134. iterator -= length;
  135.  
  136. if (iterator < 0 || ladybug < 0)
  137. {
  138. break;
  139. }
  140.  
  141. if (ladybug == iterator && result[iterator] == 1)
  142. {
  143. ladybug -= length;
  144. }
  145. else
  146. {
  147. break;
  148. }
  149. }
  150. }
  151.  
  152. if (ladybug < 0 || ladybug >= result.Length)
  153. {
  154. result[index] = 0;
  155. continue;
  156. }
  157.  
  158. result[ladybug] = 1;
  159. result[index] = 0;
  160. }
  161. }
  162.  
  163. input = Console.ReadLine();
  164. }
  165.  
  166. Console.WriteLine(string.Join(' ', result));
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement