Advertisement
Stan0033

Untitled

Jun 25th, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace apps
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. //train
  12. // list of all numbers
  13. List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14. // {bob number} {power}
  15. List<int> BombAndPower = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  16. int BombNumber = BombAndPower[0];
  17. int BombPower = BombAndPower[1];
  18. // numbers equal to the bomb numbers are removed and {power} eleemnts around it are also removed
  19.  
  20.  
  21. for (int i=0; i< numbers.Count; i++) // go through all elements to see which is bombed
  22. {
  23. if (numbers[i] == BombNumber)
  24. {
  25. int ElementBombed = i; // the found index of the bombed number
  26.  
  27. for (int y=0; y<BombPower; y++) // remove X elements from each side
  28. {
  29. if (ElementBombed - 1 >= 0)
  30. {
  31. numbers.RemoveAt(ElementBombed - 1); ElementBombed--;
  32. }
  33. if (ElementBombed+1 < numbers.Count)
  34. {
  35. numbers.RemoveAt(ElementBombed + 1);
  36. }
  37.  
  38. }
  39. numbers.RemoveAt(ElementBombed); // finally remove the bombed element
  40. }
  41.  
  42. }
  43.  
  44. int SumTotal = 0;
  45. for (int i = 0; i < numbers.Count; i++) { SumTotal += numbers[i]; } // sum the elements
  46. Console.WriteLine(SumTotal); // print the sum of the remaining elements
  47.  
  48. }
  49.  
  50.  
  51.  
  52. }
  53.  
  54.  
  55. }
  56.  
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement