Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 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 practic
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int size = int.Parse(Console.ReadLine());
  14. var arrSize = new int[size];
  15.  
  16. var ladyBugs = Console.ReadLine().Split().Select(int.Parse).ToArray();
  17.  
  18. for (int a = 0; a < arrSize.Length; a++)
  19. {
  20. for (int b = 0; b < ladyBugs.Length; b++)
  21. {
  22. if (ladyBugs[b] == a)
  23. {
  24. arrSize[a] += 1;
  25. }
  26. }
  27. }
  28.  
  29. while (true)
  30. {
  31. var inpuLine = Console.ReadLine();
  32. if (inpuLine.Equals("end"))
  33. {
  34. break;
  35. }
  36. var inpuLineSplit = inpuLine.Split();
  37.  
  38. int indexBugs = int.Parse(inpuLineSplit[0]);
  39. var leftAndRight = inpuLineSplit[1];
  40. int flightBugs = int.Parse(inpuLineSplit[2]);
  41.  
  42. if (indexBugs < 0 || indexBugs >= arrSize.Length)
  43. {
  44. continue;
  45. }
  46. if (arrSize[indexBugs] == 0)
  47. {
  48. continue;
  49. }
  50. MoveLadyBugs(arrSize, indexBugs, flightBugs, leftAndRight);
  51. }
  52. Console.WriteLine(string.Join(" ", arrSize));
  53. }
  54.  
  55. private static void MoveLadyBugs(int[] arrSize, int indexBugs, int flightBugs, string leftAndRight)
  56. {
  57. arrSize[indexBugs] = 0;
  58.  
  59. var leftArrayPlace = false;
  60. while (!leftArrayPlace)
  61. {
  62. switch (leftAndRight)
  63. {
  64. case "left":
  65. indexBugs -= flightBugs;
  66. break;
  67. case "right":
  68. indexBugs += flightBugs;
  69. break;
  70. }
  71. if (indexBugs < 0 || indexBugs >= arrSize.Length)
  72. {
  73. leftArrayPlace = true;
  74. continue;
  75. }
  76. if (arrSize[indexBugs] == 1)
  77. {
  78. continue;
  79. }
  80. if (arrSize[indexBugs] == 0)
  81. {
  82. arrSize[indexBugs] = 1;
  83. leftArrayPlace = true;
  84. continue;
  85. }
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement