Advertisement
viraco4a

fixed

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