Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2._Ladybugs
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. long[] fieldSize = new long[long.Parse(Console.ReadLine().Trim())];
  12.  
  13. long[] indexesWhereTheBugsAre = Console.ReadLine().
  14. Split().
  15. Select(long.Parse).ToArray();
  16. for (int i = 0; i < fieldSize.Length; i++)
  17. {
  18. for (int j = 0; j < indexesWhereTheBugsAre.Length; j++)
  19. {
  20. if (i == indexesWhereTheBugsAre[j])
  21. {
  22. fieldSize[i] = 1;
  23. }
  24. }
  25. }
  26. while (true)
  27. {
  28. string input = Console.ReadLine();
  29. if (input == "end")
  30. {
  31. break;
  32. }
  33. string[] SplitedInput = input.Trim().Split().ToArray();
  34.  
  35. int ladyBugIndex = int.Parse(SplitedInput[0]);
  36.  
  37. string directory = SplitedInput[1];
  38. int flyLenght = int.Parse(SplitedInput[2]);
  39.  
  40. try
  41. {
  42. fieldSize[ladyBugIndex] = 0;
  43. }
  44. catch (Exception)
  45. {
  46. continue;
  47. }
  48.  
  49. int indexNewBug = 0;
  50. if (directory == "right")
  51. {
  52. indexNewBug = ladyBugIndex + flyLenght;
  53. if (fieldSize.Length > indexNewBug)
  54. {
  55. while (fieldSize.Length - 1 >= indexNewBug)
  56. {
  57. if (fieldSize[indexNewBug] == 0)
  58. {
  59. fieldSize[indexNewBug] = 1;
  60. break;
  61. }
  62. else
  63. {
  64. indexNewBug *= 2;
  65. }
  66. }
  67. }
  68. }
  69. if (directory == "left")
  70. {
  71. indexNewBug = ladyBugIndex - flyLenght;
  72. int fullSize = fieldSize.Length - 1;
  73. if (indexNewBug >=0)
  74. {
  75. while (indexNewBug >= 0)
  76. {
  77. if (fieldSize[indexNewBug] == 0)
  78. {
  79. fieldSize[indexNewBug] = 1;
  80. break;
  81. }
  82. else
  83. {
  84. indexNewBug -= flyLenght;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. Console.WriteLine(string.Join(" ", fieldSize));
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement