Guest User

Untitled

a guest
Jul 5th, 2021
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace BombNumbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> listOfIntegers = Console.ReadLine()
  12.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.  
  16.             int[] bombNumberAndPower = Console.ReadLine()
  17.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  18.                 .Select(int.Parse)
  19.                 .ToArray();
  20.  
  21.             int startIndex;
  22.             int sum = 0;
  23.  
  24.             while (listOfIntegers.Contains(bombNumberAndPower[0]))
  25.             {
  26.  
  27.                 startIndex = listOfIntegers.IndexOf(bombNumberAndPower[0]) - bombNumberAndPower[1];
  28.  
  29.                 if (startIndex < 0)             //тук
  30.                     startIndex = 0;
  31.  
  32.                 for (int i = 0; i < bombNumberAndPower[1] * 2 + 1; i++)
  33.                 {
  34.                     if (startIndex <= listOfIntegers.Count - 1)
  35.                     {
  36.                         listOfIntegers.RemoveAt(startIndex);
  37.                     }
  38.                 }
  39.  
  40.             }
  41.  
  42.             for (int i = 0; i < listOfIntegers.Count; i++)
  43.             {
  44.                 sum += listOfIntegers[i];
  45.             }
  46.  
  47.             Console.WriteLine(sum);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment