Advertisement
Guest User

Untitled

a guest
Oct 9th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace LadyBugs
  5. {
  6. class Program
  7. {
  8. //public static bool IsArrayEmpty(int[] field)
  9. //{
  10. // int sum = 0;
  11. // for (int i = 0; i < field.Length; i++)
  12. // {
  13. // sum += field[i];
  14. // }
  15.  
  16. // if (sum == 0)
  17. // {
  18. // return true;
  19. // }
  20.  
  21. // return false;
  22. //}
  23.  
  24. static void Main()
  25. {
  26. ushort size = ushort.Parse(Console.ReadLine());
  27.  
  28. int[] startIndexes = Console
  29. .ReadLine()
  30. .Split()
  31. .Select(int.Parse).
  32. ToArray();
  33.  
  34. int[] field = new int[size];
  35.  
  36. foreach (int index in startIndexes)
  37. {
  38. if (index > size - 1 || index < 0)
  39. {
  40. continue;
  41. }
  42. field[index] = 1;
  43. }
  44.  
  45. string commandAsString = "";
  46.  
  47. while ((commandAsString = Console.ReadLine()) != "end")
  48. {
  49. string[] command = commandAsString.Split();
  50. string direction = command[1];
  51. int startIndex = int.Parse(command[0]);
  52. int flyLenght = int.Parse(command[2]);
  53. int landIndex = 0;
  54.  
  55.  
  56. if (startIndex < 0 || startIndex >= size || field[startIndex] == 0)
  57. {
  58. continue;
  59. }
  60.  
  61. if (direction == "left")
  62. {
  63. landIndex = startIndex - flyLenght;
  64.  
  65. while (landIndex >= 0)
  66. {
  67. if (field[landIndex] == 0)
  68. {
  69. field[landIndex] = 1;
  70. break;
  71. }
  72. landIndex -= flyLenght;
  73. }
  74. }
  75.  
  76. else if (direction == "right")
  77. {
  78. landIndex = startIndex + flyLenght;
  79. while (landIndex < size)
  80. {
  81. if (field[landIndex] == 0)
  82. {
  83. field[landIndex] = 1;
  84. break;
  85. }
  86. landIndex += flyLenght;
  87. }
  88. }
  89.  
  90. field[startIndex] = 0;
  91.  
  92. //if (IsArrayEmpty(field))
  93. //{
  94. // break;
  95. //}
  96. }
  97.  
  98. string output = string.Join(" ", field);
  99. Console.WriteLine(output);
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement