Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _10._LadyBugs
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int sizeOfField = int.Parse(Console.ReadLine());
  11. int[] startPlace = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  12. int[] bugsOnField = new int[sizeOfField];
  13.  
  14. for (int i = 0; i < startPlace.Length; i++)
  15. {
  16. int currentposition = startPlace[i];
  17.  
  18. for (int j = 0; j < bugsOnField.Length; j++)
  19. {
  20. int positionOnField = j;
  21.  
  22. if (currentposition == positionOnField)
  23. {
  24. bugsOnField[j] = 1;
  25. break;
  26. }
  27. }
  28. }
  29. string input;
  30. while ((input = Console.ReadLine()) != "end")
  31. {
  32.  
  33. string[] command = input.Split(" ").ToArray();
  34.  
  35. int currentPosition = int.Parse(command[0]);
  36. string direction = command[1];
  37. int moveLenght = int.Parse(command[2]);
  38.  
  39. if (currentPosition < 0 || currentPosition > bugsOnField.Length - 1)
  40. {
  41. continue;
  42. }
  43.  
  44. else if (bugsOnField[currentPosition] == 1)
  45. {
  46. int indexdirection = GetDirection(direction);
  47. int newPosition = currentPosition + (moveLenght * indexdirection);
  48.  
  49. bugsOnField[currentPosition] = 0;
  50.  
  51. while (newPosition >= 0 && newPosition <= bugsOnField.Length - 1)
  52. {
  53. if (bugsOnField[newPosition] == 0)
  54. {
  55. bugsOnField[newPosition] = 1;
  56. break;
  57. }
  58. else
  59. {
  60. newPosition += moveLenght * indexdirection;
  61. }
  62. }
  63. }
  64. }
  65. Console.WriteLine(string.Join(" ", bugsOnField));
  66. }
  67. private static int GetDirection(string direction)
  68. {
  69. int indexDirection = 1;
  70. if (direction == "left")
  71. {
  72. indexDirection = -1;
  73. }
  74. return indexDirection;
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement