Advertisement
Guest User

Ladybugs

a guest
Feb 21st, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. namespace _02.LadyBugs
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. public class Program
  10. {
  11. public static void Main()
  12. {
  13. var sizeOfField = int.Parse(Console.ReadLine());
  14. var fieldArray = new int[sizeOfField];
  15. var positionOfLB = Console.ReadLine().Split();
  16. var command = Console.ReadLine().Split().ToArray();
  17. var justListOfLBS = new List<int>();
  18. for (int i = 0; i < positionOfLB.Length; i++)
  19. {
  20. justListOfLBS.Add(int.Parse(positionOfLB[i]));
  21. }
  22. foreach (var lb in justListOfLBS)
  23. {
  24. if (fieldArray.Length >= lb + 1)
  25. {
  26. fieldArray[lb] = 1;
  27. }
  28. else
  29. {
  30. continue;
  31. }
  32. }
  33.  
  34. while (command[0] != "end")
  35. {
  36.  
  37.  
  38. var commandLBI = int.Parse(command[0]);
  39. var commandLBD = command[1];
  40. var commandLBFlyLength = int.Parse(command[2]);
  41. if (fieldArray.Length < commandLBI + 1)
  42. {
  43. //continue;
  44. }
  45. else if (fieldArray[commandLBI] == 0)
  46. {
  47. //continue;
  48. }
  49. else
  50. {
  51. if (commandLBD == "left")
  52. {
  53. var newPositionIndex = commandLBI - commandLBFlyLength;
  54. if (newPositionIndex < 0)
  55. {
  56. //continue;
  57. }
  58. else if (fieldArray.Length > newPositionIndex + 1)
  59. {
  60. fieldArray[commandLBI] = 0;
  61. }
  62. else
  63. {
  64.  
  65. if (fieldArray[newPositionIndex] == 1)
  66. {
  67. newPositionIndex += 1;
  68. if (fieldArray[newPositionIndex] == 1)
  69. {
  70. newPositionIndex += 1;
  71. fieldArray[commandLBI] = 0;
  72. fieldArray[newPositionIndex] = 1;
  73. }
  74. fieldArray[commandLBI] = 0;
  75. fieldArray[newPositionIndex] = 1;
  76. }
  77. }
  78. }
  79. else if (commandLBD == "right")
  80. {
  81. var newPositionIndex = commandLBI + commandLBFlyLength;
  82. if (fieldArray.Length >= newPositionIndex + 1)
  83. {
  84. if (fieldArray[newPositionIndex] == 1)
  85. {
  86. newPositionIndex += 1;
  87. if (fieldArray.Length > newPositionIndex + 1)
  88. {
  89. fieldArray[commandLBI] = 0;
  90. //continue;
  91. }
  92.  
  93. else if (fieldArray[newPositionIndex] == 1 && fieldArray.Length <= newPositionIndex + 1)
  94. {
  95. newPositionIndex += 1;
  96. fieldArray[commandLBI] = 0;
  97. fieldArray[newPositionIndex] = 1;
  98. }
  99.  
  100. fieldArray[commandLBI] = 0;
  101. fieldArray[newPositionIndex] = 1;
  102. }
  103. }
  104. else if (fieldArray.Length > newPositionIndex + 1)
  105. {
  106. fieldArray[commandLBI] = 0;
  107. }
  108. else
  109. {
  110. //continue;
  111. }
  112. }
  113. }
  114.  
  115.  
  116. command = Console.ReadLine().Split().ToArray();
  117. }
  118.  
  119. Console.WriteLine(string.Join(" ",fieldArray));
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement