Advertisement
vasildiavolo

ladybugs

May 25th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int size = int.Parse(Console.ReadLine());
  10. int[] field = new int[size];
  11. int[] indexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12. foreach (var index in indexes)
  13. {
  14. if (index < field.Length)
  15. {
  16. field[index] = 1;
  17. }
  18. }
  19.  
  20. string[] input = Console.ReadLine().Split().ToArray();
  21. while (input[0] != "end")
  22. {
  23. int indexToMove = int.Parse(input[0]);
  24.  
  25. bool indexOutOfRange = indexToMove < 0 || indexToMove > field.Length - 1;
  26. bool ladybugMiss = field[indexToMove] == 0;
  27. if (indexOutOfRange || ladybugMiss)
  28. {
  29. input = Console.ReadLine().Split().ToArray();
  30. continue;
  31. }
  32.  
  33. string direction = input[1];
  34. int fly = int.Parse(input[2]);
  35.  
  36. if (fly < 0)
  37. {
  38. if (direction == "right")
  39. {
  40. direction = "left";
  41. }
  42. else
  43. {
  44. direction = "right";
  45. }
  46.  
  47. fly = Math.Abs(fly);
  48. }
  49.  
  50.  
  51.  
  52. input = Console.ReadLine().Split().ToArray();
  53. }
  54.  
  55. Console.WriteLine(string.Join(" ", field));
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement