Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

nd_nikolov avatar nd_nikolov 7 Точки

Mid Exam Python "Array Modifier"?!

Здравейте, някой има ли обяснение защо на решението на посочената задача Judge дава 0/100, при излезли преди това нулеви тестове и debug в пълен синхрон с указанията? В същото време ми дава 40/100 на незавършено решение(посочено в края).

02. Array Modifier

You are given an array with integers. Write a program to modify the elements after receive the commandsswap”, “multiply” or “decrease”.

  • “swap {index1} {index2}” take two elements and swap their places.
  • “multiply {index1} {index2}” take element at the 1st index and multiply it with element at 2nd index. Save the product at the 1st index.
  • “decrease” decreases all elements in the array with 1.

Input

On the first input line you will be given the initial array values separated by a single space.

On the next lines you will receive commands until you receive the command “end”. The commands are as follow:

  • “swap {index1} {index2}”
  • “multiply {index1} {index2}”
  • “decrease”

Output

The output should be printed on the console and consist element of the modified arrayseparated by “, “(comma and single space).

Constraints

  • Commands will be: “swap”, “multiply”, “decrease” and “end
  • Elements of the array will be integer numbers in the range [-231...231]
  • Count of the array elements will be in the range [2...100]
  • Indexes will be always in the range of the array

Examples

Input

Output

Comments

23 -2 321 87 42 90 -123

swap 1 3

swap 3 6

swap 1 0

multiply 1 2

multiply 2 1

decrease

end

86, 7382, 2369942, -124, 41, 89, -3

23 -2 321 87 42 90 -123 – initial values

swap 1(-2) and 3(87) ▼

23 87 321 -2 42 90 -123

swap 3(-2) and 6(-123) ▼

23 87 321 -123 42 90 -2

swap 1(87) and 0(23) ▼

87 23 321 -123 42 90 -2

multiply 1(23) 2(321) = 7383 ▼

87 7383 321 -123 42 290 -2

multiply 2(321) 1(7383) = 2369943 ▼

87 7383 2369943 -123 42 90 -2

decrease – all - 1 ▼

86 7383 2369942 -124 41 89 -3

1 2 3 4

swap 0 1

swap 1 2

swap 2 3

multiply 1 2

decrease

end

1, 11, 3, 0

 

Решение 0/100

array = input().split()
command = input().split()
amount = 0
new_array = []

while not command == "end":
    if command[0] == "swap":
        array[int(command[1])], array[int(command[2])] = array[int(command[2])], array[int(command[1])]
    elif command[0] == "multiply":
        amount = int(array[int(command[1])]) * int(array[int(command[2])])
        array.remove(array[int(command[1])])
        array.insert(int(command[1]), str(amount))
    elif command[0] == "decrease":
        for item in array:
            new_array.append(int(item) - 1)
    command = input().split()
    if command[0] == "end":
        break
print(", ".join(map(str, new_array)))

 

Решение 40/100

array = input().split()
command = input().split()
amount = 0
while not command == "end":
    if command[0] == "swap":
        array[int(command[1])], array[int(command[2])] = array[int(command[2])], array[int(command[1])]
    if command[0] == "multiply":
        amount = int(array[int(command[1])]) * int(array[int(command[2])])
        array.insert(int(command[1]), str(amount))
        array.remove(array[int(command[2])])
    if command[0] == "decrease":
        decreased_array = [int(x)-1 for x in array]
    if command[0] == "end":
        break
    command = input().split()
print(", ".join(map(str, array)))

Предварително благодаря за отделеното време и направените усилия!

Тагове:
0
Python Fundamentals 08/07/2020 14:25:30
Pe6ko13 avatar Pe6ko13 8 Точки

https://pastebin.com/1rpGR63x

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