Advertisement
bacco

Bomb Numbers

Jun 5th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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.             List<int> nums = Console.ReadLine()
  13.                                     .Split(' ')
  14.                                     .Select(int.Parse)
  15.                                     .ToList();
  16.             int[]  input = Console.ReadLine()
  17.                                   .Split(' ')
  18.                                   .Select(int.Parse)
  19.                                   .ToArray();
  20.  
  21.             int bomb  = input[0];
  22.             int range = input[1];
  23.  
  24.             int bombIndex = nums.IndexOf(bomb);
  25.  
  26.             while (bombIndex != -1)
  27.             {
  28.                 int left  = bombIndex - range;
  29.                 int right = bombIndex + range;
  30.  
  31.                 if (left < 0)
  32.                 {
  33.                     left = 0;
  34.                 }
  35.                 if (right > nums.Count - 1)
  36.                 {
  37.                     right = nums.Count - 1;
  38.                 }
  39.  
  40.                 int count = right - left + 1;
  41.                 nums.RemoveRange(left, count);
  42.                 bombIndex = nums.IndexOf(bomb);
  43.             }
  44.             int sum = 0;
  45.             foreach (var num in nums)
  46.             {
  47.                 sum += num;
  48.             }
  49.             Console.WriteLine(sum);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement