Advertisement
Guest User

BombNumber

a guest
Oct 12th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exe16BombNumbers
  6. {
  7.     public class Exe16BombNumbers
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<int> nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.             int[] bomb = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.  
  14.             while (true)
  15.             {
  16.                 if (nums.Contains(bomb[0]))
  17.                 {
  18.                     int index = nums.IndexOf(bomb[0]);
  19.  
  20.                     int indBeg = 0;
  21.                     if ((index - bomb[1]) > 0)
  22.                     {
  23.                         indBeg = index - bomb[1];
  24.                     }
  25.  
  26.                     int indEnd = (nums.Count - 1);
  27.                     if ((index + bomb[1]) < (nums.Count - 1))
  28.                     {
  29.                         indEnd = index + bomb[1];
  30.                     }
  31.  
  32.                     for (int i = indBeg; i <= indEnd; i++)
  33.                     {
  34.                         nums.RemoveAt(indBeg);
  35.                     }
  36.                 }
  37.  
  38.                 if (!nums.Contains(bomb[0]))
  39.                     break;
  40.             }
  41.  
  42.             Console.WriteLine(nums.Sum());
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement