5. Bomb Numbers/ C# Fundamentsls/Lists Exercise
Здравейте, колеги.
Бих искала да ви помоля за малко помощ за следната задача, на която изкарвам 75% в Judge с един гримнал тест и не мога да разбера защо.
using System;
using System.Collections.Generic;
using System.Linq;
namespace _05.Bomb_Numbers_2
{
class Program
{
static void Main(string[] args)
{
List<int> bombNumbers = Console.ReadLine().Split().Select(int.Parse).ToList();
List<int> specialNumPow = Console.ReadLine().Split().Select(int.Parse).ToList();
int specialNum = specialNumPow[0];
int power = specialNumPow[1];
if (bombNumbers.Contains(specialNum))
{
for (int i=0;i<bombNumbers.Count;i++)
{
if (bombNumbers[i] == specialNum)
{
int startIndex = GetStartIndex(bombNumbers, specialNum, power);
int count = GetCount(bombNumbers, specialNum, power, startIndex);
bombNumbers.RemoveRange(startIndex, count);
}
else
{
continue;
}
}
int sum = bombNumbers.Sum();
Console.WriteLine(sum);
}
else
{
return;
}
}
private static int GetStartIndex(List<int> bombNumbers, int specialNum,int power)
{
int indexSpecialNum = bombNumbers.IndexOf(specialNum);
int startIndex = 0;
if (indexSpecialNum - power >= 0)
{
startIndex = indexSpecialNum - power;
}
else
{
startIndex = 0;
}
return startIndex;
}
private static int GetCount(List<int> bombNumbers, int specialNum, int power,int startIndex)
{
int indexSpecialNum = bombNumbers.IndexOf(specialNum);
int count = 0;
if (indexSpecialNum + power <= bombNumbers.Count - 1)
{
for (int i = startIndex; i <= indexSpecialNum + power; i++)
{
count++;
}
}
else
{
for (int i = startIndex; i <= bombNumbers.Count-1; i++)
{
count++;
}
}
return count;
}
}
}
Много ще съм ви благодарна, ако споделите мнения!
Поздрави.
Дени