Advertisement
Nenogzar

numbers

Feb 18th, 2024
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. count_of_numbers = list(map(int, input().split()))
  2. command = input().split()
  3. while command[0] != "Finish":
  4.     if len(command) <= 2:
  5.         action = command[0]
  6.         value = int(command[1])
  7.         if action == "Add":
  8.             count_of_numbers.append(value)
  9.         elif action == "Remove":
  10.             count_of_numbers.remove(value)
  11.         elif action == "Collapse":
  12.             for i in count_of_numbers:
  13.                 if i < value:
  14.                     count_of_numbers.remove(i)
  15.     elif len(command) > 2:
  16.         value = int(command[1])
  17.         replacement = int(command[2])
  18.  
  19.         index = count_of_numbers.index(value)
  20.         count_of_numbers.pop(index)
  21.         count_of_numbers.insert(index, replacement)
  22.  
  23.     command = input().split()
  24.  
  25. print(*count_of_numbers, sep=" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement