Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- houses = input().split()
- index = 0
- for i in range(n):
- current_command = input().split()
- command = current_command[0]
- current_index = index
- if command in ('Forward', 'Back'):
- steps = int(current_command[1])
- current_index += steps if command == 'Forward' else -steps
- if 0 <= current_index < len(houses):
- houses.pop(current_index)
- index = current_index
- elif command == 'Gift':
- current_index = int(current_command[1])
- if 0 <= current_index < len(houses):
- houses.insert(current_index, current_command[2])
- index = current_index
- elif command == 'Swap':
- index1 = houses.index(current_command[1])
- index2 = houses.index(current_command[2])
- if 0 <= index1 < len(houses) and 0 <= index2 < len(houses) and index1 != index2:
- houses[index1], houses[index2] = houses[index2], houses[index1]
- print(f'Position: {index}\n{", ".join(houses)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement