Advertisement
Guest User

07_Bomb_numbers

a guest
Aug 28th, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07_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.             List<int> commands = Console.ReadLine().Split().Select(int.Parse).ToList();
  13.  
  14.             for (int i = 0; i < numbers.Count; i++)
  15.             {
  16.                 if (numbers[i] == commands[0])
  17.                 {
  18.                     int start = i - commands[1];
  19.                     if (start < 0)
  20.                     {
  21.                         start = 0;
  22.                     }
  23.  
  24.                     int finish = i + commands[1] + 1;
  25.                     if (finish > numbers.Count)
  26.                     {
  27.                         finish = numbers.Count;
  28.                     }
  29.  
  30.                     for (int j = start; j < finish; j++)
  31.                     {
  32.                         numbers[j] = 0;
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             Console.WriteLine(numbers.Sum());
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement