Loading...
Worms123 avatar Worms123 0 Точки

10. *Pokemon Don't Go List Advanced Python

Ще се радвам ако някой може да открие грешката в кода ми за тази задача. Изкарвам 80/100 точки, но не мога да намеря къде е проблема в точно този код.

https://pastebin.com/sD7JRV6e

https://judge.softuni.org/Contests/Compete/Index/1731#9

Условие:

You will receive a sequence of integers, separated by spaces - the distances to the pokemon. Then you will begin receiving integers, which will correspond to indexes in that sequence.

When you receive an index, you must remove the element at that index from the sequence (as if you've captured the pokemon).

  • You must increase the value of all elements in the sequence which are less or equal to the removed element with the value of the removed element.
  • You must decrease the value of all elements in the sequence which are greater than the removed element with the value of the removed element.

If the given index is less than 0, remove the first element of the sequence, and copy the last element to its place.

If the given index is greater than the last index of the sequence, remove the last element from the sequence, and copy the first element to its place.

The increasing and decreasing elements should also be done in these cases. The element whose value you should use is the removed element.

The program ends when the sequence has no elements (there are no pokemon left for Ely to catch).

Input

  • On the first line of input, you will receive a sequence of integers, separated by spaces.
  • On the next several lines, you will receive integers - the indexes.

Output

  • When the program ends, you must print the summed value of all removed elements.

Constrains

The input data will consist only of valid integers in the range [-2.147.483.648…2.147.483.647].

Тагове:
0
Python Fundamentals
valerielashvili avatar valerielashvili 22 Точки

Добавям и моето решение:

pokemons = [int(x) for x in input().split()]
elements_sum = 0

while len(pokemons) != 0:
    index = int(input())
    last_index = len(pokemons) - 1
    removed_element_value = 0

    if index < 0:
        index = 0
        removed_element_value = pokemons[index]
        pokemons[index] = pokemons[last_index]
    elif index > last_index:
        removed_element_value = pokemons[last_index]
        pokemons[last_index] = pokemons[0]
    else:
        removed_element_value = pokemons.pop(index)

    pokemons = [
        p + removed_element_value if p <= removed_element_value else
        p - removed_element_value if p > removed_element_value else p
        for p in pokemons
        ]
    
    elements_sum += removed_element_value

print(elements_sum)

 

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.