fork download
  1. namespace _02.Lady_Bugs
  2. {
  3. using System;
  4. using System.Linq;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. var sizeList = int.Parse(Console.ReadLine());
  11. var inputLadybugIndexes = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12. var param = Console.ReadLine().Split(' ').ToArray();
  13.  
  14. var array = new int[sizeList];
  15.  
  16. //setting the indexes of the ladybugs
  17. foreach (var index in inputLadybugIndexes)
  18. {
  19. if (index >= 0 && index < array.Length)
  20. {
  21. array[index] = 1;
  22. }
  23. }
  24.  
  25. while (param[0] != "end")
  26. {
  27. var ladybugIndex = int.Parse(param[0]);
  28. var direction = param[1];
  29. var flyLength = int.Parse(param[2]);
  30.  
  31. //if there is a ladybug at the inputted index:
  32. if (ladybugIndex >= 0 && ladybugIndex < array.Length && array[ladybugIndex] == 1)
  33. {
  34. array[ladybugIndex] = 0;
  35.  
  36. if (direction == "right")
  37. {
  38. MoveToRight(flyLength, ladybugIndex, array);
  39. }
  40.  
  41. else
  42. {
  43. MoveToLeft(flyLength, ladybugIndex, array);
  44. }
  45. }
  46.  
  47. param = Console.ReadLine().Split(' ').ToArray();
  48. }
  49.  
  50. Console.WriteLine(string.Join(" ", array));
  51. }
  52.  
  53. static void MoveToRight(int flyLength, int ladybugIndex, int[] array)
  54. {
  55. if (flyLength >= 0)
  56. {
  57. while (ladybugIndex + flyLength < array.Length)
  58. {
  59. if (array[ladybugIndex + flyLength] != 1)
  60. {
  61. array[ladybugIndex + flyLength] = 1;
  62. break;
  63. }
  64.  
  65. ladybugIndex++;
  66. }
  67. }
  68.  
  69. else
  70. {
  71. while (ladybugIndex - Math.Abs(flyLength) < array.Length && ladybugIndex - Math.Abs(flyLength) >= 0)
  72. {
  73. if (array[ladybugIndex - Math.Abs(flyLength)] != 1)
  74. {
  75. array[ladybugIndex - Math.Abs(flyLength)] = 1;
  76. break;
  77. }
  78.  
  79. ladybugIndex--;
  80. }
  81. }
  82. }
  83.  
  84. static void MoveToLeft(int flyLength, int ladybugIndex, int[] array)
  85. {
  86. if (flyLength >= 0)
  87. {
  88. while (ladybugIndex - flyLength < array.Length && ladybugIndex - flyLength >= 0)
  89. {
  90. if (array[ladybugIndex - flyLength] != 1)
  91. {
  92. array[ladybugIndex - flyLength] = 1;
  93. break;
  94. }
  95.  
  96. ladybugIndex--;
  97. }
  98. }
  99.  
  100. else
  101. {
  102. while (ladybugIndex + Math.Abs(flyLength) < array.Length && ladybugIndex + Math.Abs(flyLength) >= 0)
  103. {
  104. if (array[ladybugIndex + Math.Abs(flyLength)] != 1)
  105. {
  106. array[ladybugIndex + Math.Abs(flyLength)] = 1;
  107. break;
  108. }
  109.  
  110. ladybugIndex++;
  111. }
  112. }
  113. }
  114. }
  115. }
Runtime error #stdin #stdout #stderr 0.01s 135744KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: String
  at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00006] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Int32.Parse (System.String s) [0x00007] in <8f2c484307284b51944a1a13a14c0266>:0 
  at _02.Lady_Bugs.Program.Main () [0x00005] in <5409a61a748e4a0ab8c35d18d851e112>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Value cannot be null.
Parameter name: String
  at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00006] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Int32.Parse (System.String s) [0x00007] in <8f2c484307284b51944a1a13a14c0266>:0 
  at _02.Lady_Bugs.Program.Main () [0x00005] in <5409a61a748e4a0ab8c35d18d851e112>:0