simonradev

LadyBugs

Nov 7th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace CheatSheet
  5. {
  6. class Program
  7. {
  8. public static void Main(string[] args)
  9. {
  10. int size = int.Parse(Console.ReadLine());
  11. int[] ladyBugs = new int[size];
  12. int[] placesOfLadyBugs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.  
  14. int ladyBugPlaceHolder = 0;
  15. for (int currentElement = 0; currentElement < placesOfLadyBugs.Length; currentElement++)
  16. {
  17. ladyBugPlaceHolder = placesOfLadyBugs[currentElement];
  18.  
  19. ladyBugs[ladyBugPlaceHolder] = 1;
  20. }
  21.  
  22. while (true)
  23. {
  24. string[] command = Console.ReadLine().Split(' ').ToArray();
  25.  
  26. if (command[0] != "end")
  27. {
  28. int curretPosition = int.Parse(command[0]);
  29. string direction = command[1];
  30. int cellsToMove = int.Parse(command[2]);
  31. int finalCellForABug = (curretPosition + cellsToMove);
  32. bool movementFinished = false;
  33.  
  34. if (direction == "right")
  35. {
  36. while (!movementFinished)
  37. {
  38. if (ladyBugs[curretPosition] == 0)
  39. {
  40. movementFinished = true;
  41. }
  42. else if (ladyBugs[curretPosition] != 0)
  43. {
  44. if (finalCellForABug >= ladyBugs.Length)
  45. {
  46. ladyBugs[curretPosition] = 0;
  47. movementFinished = true;
  48. }
  49. else
  50. {
  51. ladyBugs[curretPosition] = 0;
  52. ladyBugs[finalCellForABug] = 1;
  53. movementFinished = true;
  54. }
  55. }
  56.  
  57. }
  58. }
  59. }
  60. else
  61. {
  62. break;
  63. }
  64. }
  65.  
  66. Console.WriteLine(string.Join(" ", ladyBugs));
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment