Advertisement
elena1234

BombNumbers

Sep 21st, 2020 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace BombNumbers
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.  
  13.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.  
  15.             string command = Console.ReadLine();
  16.             string[] commandArray = command.Split();
  17.             int specialNumber = int.Parse(commandArray[0]);
  18.             int power = int.Parse(commandArray[1]);
  19.             while(numbers.Contains(specialNumber))
  20.             {
  21.                 int bombIndex = numbers.IndexOf(specialNumber);
  22.                 int leftIndex = Math.Max(0, bombIndex - power);
  23.                 int rightIndex = Math.Min(numbers.Count - 1, bombIndex + power);
  24.  
  25.                 numbers.RemoveRange(leftIndex, rightIndex - leftIndex + 1);
  26.             }
  27.  
  28.             Console.WriteLine(numbers.Sum());
  29.         }
  30.     }
  31. }
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement