Advertisement
Spocoman

02. Santa's Gifts(77/100)

Feb 12th, 2024
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. n = int(input())
  2.  
  3. houses = input().split()
  4.  
  5. index = 0
  6.  
  7. for i in range(n):
  8.     current_command = input().split()
  9.     command = current_command[0]
  10.     current_index = index
  11.  
  12.     if command in ('Forward', 'Back'):
  13.         steps = int(current_command[1])
  14.         current_index += steps if command == 'Forward' else -steps
  15.         if 0 <= current_index < len(houses):
  16.             houses.pop(current_index)
  17.             index = current_index
  18.     elif command == 'Gift':
  19.         current_index = int(current_command[1])
  20.         if 0 <= current_index < len(houses):
  21.             houses.insert(current_index, current_command[2])
  22.             index = current_index
  23.     elif command == 'Swap':
  24.         index1 = houses.index(current_command[1])
  25.         index2 = houses.index(current_command[2])
  26.         if 0 <= index1 < len(houses) and 0 <= index2 < len(houses) and index1 != index2:
  27.             houses[index1], houses[index2] = houses[index2], houses[index1]
  28.  
  29. print(f'Position: {index}\n{", ".join(houses)}')
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement