Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _05_Bomb_Numbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13.             int[] bombNumAndPower = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.             int bombNum = bombNumAndPower[0];
  15.             int bombPowerLeft = bombNumAndPower[1];
  16.             int bombPowerRight = bombNumAndPower[1];
  17.            
  18.             for (int i = 0; i < numbers.Count; i++)
  19.             {
  20.                 if (bombNum == numbers[i])
  21.                 {
  22.                     int plcsAvailLeft = i;
  23.                     int plcsAvailRight = (numbers.Count) -1 - i;
  24.  
  25.                     // BOOM LEFT
  26.                     while(plcsAvailLeft > 0 && bombPowerLeft > 0)
  27.                     {
  28.                         if(bombPowerLeft > plcsAvailLeft)
  29.                         {
  30.                             bombPowerLeft--;
  31.                             continue;
  32.                         }
  33.                         numbers.RemoveAt(i - bombPowerLeft);
  34.                         bombPowerLeft--;
  35.                         i--;
  36.                     }
  37.                     bombPowerLeft = bombNumAndPower[1];
  38.  
  39.                     // BOOM RIGHT
  40.                     while (plcsAvailRight > 0 && bombPowerRight > 0)
  41.                     {
  42.                         if(bombPowerRight > plcsAvailRight)
  43.                         {
  44.                             bombPowerRight--;
  45.                             continue;
  46.                         }
  47.                         numbers.RemoveAt(i + bombPowerRight);
  48.                         bombPowerRight--;
  49.                     }
  50.                     bombPowerRight = bombNumAndPower[1];
  51.                 }
  52.             }
  53.  
  54.             // BOOM THE NUMBER
  55.             numbers.RemoveAll(bomb => bomb == bombNum);
  56.  
  57.             Console.WriteLine(String.Join(" ", numbers.Sum()));
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement