miroslavbstoyanov

Untitled

Nov 4th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.Ladybugs
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int sizeOftheField = int.Parse(Console.ReadLine());
  14. long[] indexOfLadybugs = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
  15.  
  16. long[] field = new long[sizeOftheField];
  17. for (int i = 0; i < field.Length; i++)
  18. {
  19. if (indexOfLadybugs.Contains(i))
  20. {
  21. field[i] = 1;
  22. }
  23. }
  24.  
  25. string command = "";
  26. while ((command = Console.ReadLine()) != "end")
  27. {
  28. string[] splitCommand = command.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  29. long index = long.Parse(splitCommand[0]);
  30. string commandToFly = splitCommand[1];
  31. long flyLenght = long.Parse(splitCommand[2]);
  32.  
  33. if(index > field.Length - 1 || index < 0)
  34. {
  35. continue;
  36. }
  37.  
  38.  
  39. if (commandToFly == "left")
  40. {
  41. FlyLeft(field, index, flyLenght);
  42. }
  43. else if(commandToFly == "right")
  44. {
  45. FlyRight(field, index, flyLenght);
  46. }
  47. Console.WriteLine(String.Join(" ", field));
  48.  
  49. }
  50. Console.WriteLine(String.Join(" ", field));
  51. }
  52.  
  53. private static void FlyRight(long[] field, long index, long flyLenght)
  54. {
  55. if (field[index] == 1)
  56. {
  57. field[index] = 0;
  58. }
  59. else
  60. {
  61. return;
  62. }
  63.  
  64. while (true)
  65. {
  66. if (index + flyLenght < 0 || index + flyLenght > field.Length -1)
  67. {
  68. return;
  69. }
  70. else if (field[index + flyLenght] == 0)
  71. {
  72. field[index+flyLenght] = 1;
  73. break;
  74. }
  75. else
  76. {
  77. flyLenght += flyLenght;
  78. }
  79. }
  80.  
  81. }
  82.  
  83. private static void FlyLeft(long[] field, long index, long flyLenght)
  84. {
  85. if (field[index] == 1)
  86. {
  87. field[index] = 0;
  88. }
  89. else
  90. {
  91. return;
  92. }
  93.  
  94. while (true)
  95. {
  96. if (index - flyLenght < 0 || index - flyLenght > field.Length - 1)
  97. {
  98. return;
  99. }
  100. else if (field[index - flyLenght] == 0)
  101. {
  102. field[index - flyLenght] = 1;
  103. break;
  104. }
  105. else
  106. {
  107. flyLenght -= flyLenght;
  108. }
  109. }
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment