Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _12.Bomb_Numbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> nums = Console.ReadLine().Split().Select(int.Parse).ToList();
- int[] bombNumber = Console.ReadLine().Split().Select(int.Parse).ToArray();
- List<int> afterExplosions = detonateTheBomb(nums, bombNumber);
- //Console.WriteLine(string.Join(" ", afterExplosions));
- long sum = afterExplosions.Sum();
- Console.WriteLine(sum);
- }
- private static List<int> detonateTheBomb(List<int> nums, int[] bombNumber)
- {
- int bomb = bombNumber[0];
- int power = bombNumber[1];
- int bombIndex = int.MinValue;
- bool isThereABombOrNot = true;
- while (isThereABombOrNot)
- {
- for (int item = 0; item < nums.Count; item++)
- {
- //finding the index of the bomb
- if (nums[item] == bomb)
- {
- bombIndex = item;
- }
- }//end of for
- int length = nums.Count;
- int left = power;
- int right = power;
- //detonating indexes
- if (bombIndex + 1 - left > 0&& bombIndex + 1 + right < length)
- {
- nums.RemoveRange(bombIndex - left, left + right + 1);
- }
- else if (bombIndex + 1 - left <= 0)
- {
- while (bombIndex + 1 - left <= 0)
- {
- left--;
- }
- nums.RemoveRange(bombIndex - left, left + right + 1);
- }
- else if (bombIndex+1+right>length)
- {
- while (bombIndex + 1 + right > length)
- {
- right--;
- }
- nums.RemoveRange(bombIndex - left, left + right + 1);
- }
- //checking for another bomb
- for (int item = 0; item < nums.Count; item++)
- {
- //finding the index of the bomb
- if (nums[item] == bomb)
- {
- isThereABombOrNot = true;
- bombIndex = item;
- break;
- }
- else
- {
- isThereABombOrNot = false;
- }
- }//end of for
- }//end of while
- return nums;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement