koteshkoeziche

03. Easter Shopping

Oct 30th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. shops = input().split()
  2.  
  3. n = int(input())
  4.  
  5. for i in range(n):
  6. tokens = input().split()
  7.  
  8. command = tokens[0]
  9.  
  10. if command == "Include":
  11. shop = tokens[1]
  12. shops.append(shop)
  13.  
  14. elif command == "Visit":
  15. first_or_last = tokens[1]
  16. count = int(tokens[2])
  17.  
  18. if first_or_last == "first":
  19. if count in range(len(shops)):
  20. del shops[:count]
  21. else:
  22. continue
  23.  
  24. if first_or_last == "last":
  25. if count in range(len(shops)):
  26. del shops[len(shops) - count:]
  27. else:
  28. continue
  29.  
  30. elif command == "Prefer":
  31. first_index = int(tokens[1])
  32. second_index = int(tokens[2])
  33.  
  34. if first_index in range(len(shops)) and second_index in range(len(shops)):
  35. shops[first_index], shops[second_index] = shops[second_index], shops[first_index]
  36.  
  37. elif command == "Place":
  38. shop = tokens[1]
  39. shop_index = int(tokens[2])
  40.  
  41. if shop_index in range(len(shops)):
  42. shops.insert(shop_index + 1, shop)
  43.  
  44. print('Shops left:')
  45. print(' '.join(shops))
  46.  
Advertisement
Add Comment
Please, Sign In to add comment