alexbancheva

Bomb Numbers

Jun 14th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Bomb_Numbers_Lits_Exercises
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             List<int> nums = Console.ReadLine()
  13.                 .Split()
  14.                 .Select(int.Parse)
  15.                 .ToList();
  16.  
  17.             int[] bombNum = Console.ReadLine()
  18.                 .Split()
  19.                 .Select(int.Parse)
  20.                 .ToArray();
  21.  
  22.            // string[] splitedBombNum = bombNum.Split(" ");
  23.             int specialNum = bombNum[0];
  24.             int power = bombNum[1];
  25.  
  26.             while (nums.Contains(specialNum))
  27.             {
  28.  
  29.                 int index = nums.IndexOf(specialNum);
  30.  
  31.                 if (index < power)
  32.                 {
  33.                     nums.RemoveRange(0, index);
  34.                 }
  35.                 else
  36.                 {
  37.                     nums.RemoveRange(index - power, power);
  38.                 }
  39.  
  40.                 index = nums.IndexOf(specialNum);
  41.  
  42.                 if (index + power + 1 < nums.Count)
  43.                 {
  44.                     nums.RemoveRange(index, power + 1);
  45.                 }
  46.                 else
  47.                 {
  48.                     nums.RemoveRange(index, nums.Count - index);
  49.                 }
  50.  
  51.             }
  52.  
  53.             Console.WriteLine(nums.Sum());
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment