Advertisement
bullit3189

Bomb Numbers - Lists

Jan 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _05BombNumbers
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12. List<int> bombProps = Console.ReadLine().Split().Select(int.Parse).ToList();
  13.  
  14. int bomb = bombProps[0];
  15. int power = bombProps[1];
  16.  
  17. for (int i = 0; i < numbers.Count; i++)
  18. {
  19. int currNum = numbers[i];
  20.  
  21. if (currNum==bomb)
  22. {
  23. int startIndex = i - power;
  24. int endIndex = i + power;
  25.  
  26. if (startIndex<0)
  27. {
  28. startIndex = 0;
  29. }
  30. if (endIndex>numbers.Count-1)
  31. {
  32. endIndex = numbers.Count - 1;
  33. }
  34. if (startIndex>numbers.Count-1 || endIndex<0)
  35. {
  36. continue;
  37. }
  38.  
  39. numbers.RemoveRange(startIndex, endIndex-startIndex+1);
  40. i =-1;
  41. }
  42. }
  43.  
  44. int sum = numbers.Sum();
  45.  
  46. Console.WriteLine(sum);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement