Професионална програма
Loading...
+ Нов въпрос
Axiomatik avatar Axiomatik 1626 Точки
Best Answer

Just iterate back at line 34 with i-- and your code gives 100%.

                input.RemoveAt(i);

                i--;
        for (int i = 0; i < input.Count; i++)
        {
            if (input[i] == power[0])
            {
                for (int k = 0; k < power[1]; k++)
                {
                    if (i - 1 >= 0)
                    {
                        input.RemoveAt(i - 1);
                        i--;
                    }
                }
                for (int k = 0; k < power[1]; k++)
                {
                    if (i + 1 < input.Count)
                    {
                        input.RemoveAt(i + 1);
                    }
                }
                input.RemoveAt(i);

                i--;
            }
        }

 

When deleting an element from a given collection, you will risk jumping over the next element when the loop-counter has not been set back by one position.

 

0
DoroteyaDoncheva avatar DoroteyaDoncheva 11 Точки

Благодаря много!

1