Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace LadyBug
  4. {
  5. class Program
  6. {
  7. static void mooveRight(int[] arr, int index, int steps)
  8. {
  9. if ((index + steps) < arr.Length)
  10. {
  11. arr[index] = 0;
  12.  
  13. for (int i = index+steps; i < arr.Length ; i += steps)
  14. {
  15. if (arr[i] == 0)
  16.  
  17. {
  18. arr[i] = 1;
  19. break;
  20. }
  21. }
  22. }
  23. else arr[index] = 0;
  24. }
  25. static void mooveLeft(int[] arr, int index, int steps)
  26. {
  27. if ((index - steps) >=0)
  28. {
  29. arr[index] = 0;
  30.  
  31. for (int i = index-steps; i > -1; i -= steps)
  32. {
  33. if (arr[i] ==0)
  34.  
  35. {
  36. arr[i] = 1;
  37. break;
  38. }
  39. }
  40. }
  41. else arr[index] = 0;
  42. }
  43. static void Main(string[] args)
  44. {
  45. int sizeOfField = int.Parse(Console.ReadLine());
  46. int[] field = new int[sizeOfField];
  47. for (int i = 0; i < field.Length; i++)
  48. {
  49. field[i] = 0;
  50. }
  51. string indexesString = Console.ReadLine();
  52. int[] arr = indexesString
  53. .Split(' ')
  54. .Select(int.Parse)
  55. .ToArray();
  56. for (int i = 0; i < arr.Length; i++)
  57. {
  58. if(arr[i]>=sizeOfField)
  59. {
  60. arr[i] = arr[i] % sizeOfField;
  61. }
  62. field[arr[i]] = 1;
  63. }
  64. string lineInput = string.Empty;
  65. while ((lineInput = Console.ReadLine()) != "end")
  66. {
  67. string[] input = lineInput.Split().ToArray();
  68. int index = int.Parse(input[0]);
  69. string direction = input[1];
  70. int flyLength = int.Parse(input[2]);
  71. if (index >= 0 && index < sizeOfField&& field[index]==1)
  72. {
  73. if (flyLength < 0 && direction == "left")
  74. {
  75. flyLength = Math.Abs(flyLength);
  76. mooveRight(field, index, flyLength);
  77. }
  78. if (flyLength < 0 && direction == "right")
  79. {
  80. flyLength = Math.Abs(flyLength);
  81. mooveLeft(field, index, flyLength);
  82. }
  83. if (direction == "right" && flyLength > 0)
  84. {
  85. mooveRight(field, index, flyLength);
  86. }
  87. if (direction == "left" && flyLength > 0)
  88. {
  89. mooveLeft(field, index, flyLength);
  90. }
  91. }
  92. }
  93. Console.WriteLine(string.Join(' ', field));
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement