Guest User

Untitled

a guest
May 26th, 2020
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. List<int> targets = Console.ReadLine()
  11. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  12. .Select(int.Parse)
  13. .ToList();
  14.  
  15. string input;
  16. int shotTargets = 0;
  17. int currentTarget = 0;
  18. while ((input = Console.ReadLine()) != "End")
  19. {
  20. string[] tokens = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  21. string command = tokens[0];
  22. int index = int.Parse(tokens[1]);
  23. bool indexExists = false;
  24. ShootTarget(targets, ref shotTargets, ref currentTarget, tokens, command, index, ref indexExists);
  25. indexExists = AddTarget(targets, tokens, command, index, indexExists);
  26. indexExists = Strike(targets, tokens, command, index, indexExists);
  27. }
  28. Console.WriteLine(string.Join("|", targets));
  29. }
  30.  
  31. private static bool Strike(List<int> targets, string[] tokens, string command, int index, bool indexExists)
  32. {
  33. if (command.Contains("Strike"))
  34. {
  35. for (int i = 0; i < targets.Count; i++)
  36. {
  37. if (index == i)
  38. {
  39. indexExists = true;
  40. if (indexExists)
  41. {
  42. int radius = int.Parse(tokens[2]);
  43. int targetsToStrikeRight = 0;
  44. int targetsToStrikeLeft = 0;
  45. for (int j = index + 1; j < targets.Count; j++)
  46. {
  47. targetsToStrikeRight++;
  48. if (targetsToStrikeRight == radius)
  49. {
  50. break;
  51. }
  52. }
  53. for (int k = index - 1; k >= 0; k--)
  54. {
  55. targetsToStrikeLeft++;
  56. if (targetsToStrikeLeft == radius)
  57. {
  58. break;
  59. }
  60. }
  61. if (radius == targetsToStrikeLeft && radius == targetsToStrikeRight)
  62. {
  63. if (targetsToStrikeLeft + targetsToStrikeRight == targets.Count - 1)
  64. {
  65. Console.WriteLine("Strike missed!");
  66. }
  67. else
  68. {
  69. for (int n = 0; n < radius + index; n++)
  70. {
  71. for (int m = 0; m < targets.Count; m++)
  72. {
  73. if (m == index - radius)
  74. {
  75. targets.RemoveAt(index - radius);
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. }
  82.  
  83. else
  84. {
  85. Console.WriteLine("Strike missed!");
  86. }
  87. }
  88. }
  89. }
  90. if (indexExists == false)
  91. {
  92. Console.WriteLine("Strike missed!");
  93. }
  94. }
  95.  
  96. return indexExists;
  97. }
  98.  
  99. private static bool AddTarget(List<int> targets, string[] tokens, string command, int index, bool indexExists)
  100. {
  101. if (command.Contains("Add"))
  102. {
  103. for (int i = 0; i < targets.Count; i++)
  104. {
  105. if (index == i)
  106. {
  107. indexExists = true;
  108. }
  109. if (indexExists)
  110. {
  111. int value = int.Parse(tokens[2]);
  112. targets.Insert(index, value);
  113. break;
  114. }
  115. }
  116. if (indexExists == false)
  117. {
  118. Console.WriteLine("Invalid placement!");
  119. }
  120. }
  121.  
  122. return indexExists;
  123. }
  124.  
  125. private static void ShootTarget(List<int> targets, ref int shotTargets, ref int currentTarget, string[] tokens, string command, int index, ref bool indexExists)
  126. {
  127. if (command.Contains("Shoot"))
  128. {
  129. for (int i = 0; i < targets.Count; i++)
  130. {
  131. currentTarget = targets[i];
  132. if (index == i)
  133. {
  134. indexExists = true;
  135. }
  136. if (indexExists)
  137. {
  138. int power = int.Parse(tokens[2]);
  139. currentTarget -= power;
  140. targets[i] = currentTarget;
  141. break;
  142. }
  143. }
  144. if (currentTarget <= 0)
  145. {
  146. shotTargets++;
  147. targets.Remove(currentTarget);
  148. }
  149. }
  150. }
  151. }
Add Comment
Please, Sign In to add comment