Advertisement
fr3s7ed

Untitled

Jun 21st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exam454_Ladybug
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int size = int.Parse(Console.ReadLine());
  12. int[] field = new int[size];
  13.  
  14. List<int> indexLadybug = Console.ReadLine()
  15. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  16. .Select(int.Parse)
  17. .Where(i => i >= 0 && i < size)
  18. .ToList();
  19.  
  20. foreach (var index in indexLadybug)
  21. {
  22. field[index] = 1;
  23. }
  24.  
  25. string line;
  26.  
  27. while (true)
  28. {
  29. line = Console.ReadLine();
  30.  
  31. if (line == "end")
  32. {
  33. break;
  34. }
  35.  
  36. string[] tokens = line.Split().ToArray();
  37.  
  38. int startIndex = int.Parse(tokens[0]);
  39. string direction = tokens[1];
  40. int flyLength = int.Parse(tokens[2]);
  41.  
  42. if (direction == "left")
  43. {
  44. flyLength *= -1;
  45. }
  46.  
  47. if (startIndex < 0 || startIndex >= size)
  48. {
  49. continue;
  50. }
  51.  
  52. if (field[startIndex] == 0)
  53. {
  54. continue;
  55. }
  56.  
  57. field[startIndex] = 0;
  58. int nextIndex = startIndex;
  59.  
  60. while (true)
  61. {
  62. nextIndex += flyLength;
  63.  
  64. if (nextIndex < 0 || nextIndex >= size)
  65. {
  66. break;
  67. }
  68.  
  69. if (field[nextIndex] == 1)
  70. {
  71. continue;
  72. }
  73.  
  74. field[nextIndex] = 1;
  75. break;
  76. }
  77. }
  78.  
  79. Console.WriteLine(string.Join(" ", field));
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement