Advertisement
Krum_50

Bombs Numbers

May 10th, 2021
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Bomb_Numbers
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string line = Console.ReadLine();
  12. string power = Console.ReadLine();
  13. int bomb;
  14. int power1;
  15. int sum = 0;
  16. int [] lineSplit = line.Split().Select(int.Parse).ToArray();
  17. int [] powerSplit= power.Split().Select(int.Parse).ToArray();
  18. bomb = powerSplit[0];
  19. power1 = powerSplit[1];
  20.  
  21. for (int i = 0; i <lineSplit.Length; i++)
  22. {
  23.  
  24. if (lineSplit[i] == bomb)
  25. {
  26. lineSplit[i] = 0;
  27. for (int j = 1; j <= power1; j++)
  28. {
  29.  
  30. if (i - j >= 0)
  31. {
  32. lineSplit[i - j] = 0;
  33. }
  34. if (i + j <= lineSplit.Length - 1)
  35. {
  36. lineSplit[i + j] = 0;
  37. }
  38. }
  39. }
  40.  
  41. }
  42. foreach (var number in lineSplit)
  43. {
  44. sum += number;
  45. }
  46. Console.WriteLine(sum);
  47. }
  48. }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement