Advertisement
martinvalchev

Bomb_Numbers

Feb 11th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Bomb_Numbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.             int[] comands = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  15.  
  16.             int bomb = comands[0];
  17.             int range = comands[1];
  18.  
  19.  
  20.             for (int i = 0; i < numbers.Count; i++)
  21.             {
  22.                 if (numbers[i] == bomb)
  23.                 {
  24.                     for (int j = Math.Max(i - range, 0); j <= Math.Min(i + range, numbers.Count - 1); j++)
  25.                     {
  26.                         numbers[j] = 0;
  27.                     }
  28.                 }
  29.             }
  30.             Console.WriteLine(numbers.Sum());
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement