AlexTasev

07_BombNumbers

Jun 6th, 2018
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07_BombNumbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             // Read the input - List of Integers, Array- Bomb number [0]; Power[1];
  12.             // Remove elements form left and right of the bomb element - for loops to power and RemoveAt();
  13.             // Remove the bomb numbers- Remove();
  14.             // Check if not out of range;
  15.             // Sum remining elements;
  16.  
  17.             var list = Console.ReadLine().Split().Select(int.Parse).ToList();
  18.             int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
  19.             int bomb = arr[0];
  20.             int power = arr[1];
  21.  
  22.             for (int index = 0; index < list.Count; index++)
  23.             {
  24.                 if (list[index] == bomb)
  25.                 {
  26.                     for (int i = 0; i < power; i++)
  27.                     {
  28.                         if (index < list.Count)
  29.                         {
  30.                             list.RemoveAt(index + 1);
  31.                         }
  32.                     }
  33.  
  34.                     for (int i = 0; i < power; i++)
  35.                     {
  36.                         if (index > 0)
  37.                         {
  38.                             list.RemoveAt(index - 1);
  39.                             index--;
  40.                         }
  41.                     }
  42.                 }
  43.             }
  44.  
  45.             for (int i = 0; i < list.Count; i++)
  46.             {
  47.                 list.Remove(bomb);
  48.             }
  49.  
  50.             int sum = 0;
  51.  
  52.             for (int i = 0; i < list.Count; i++)
  53.             {
  54.                 sum += list[i];
  55.             }
  56.  
  57.             Console.WriteLine(sum);
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment