sibinasto

Problem 6 - Luxuty Coffee

Mar 7th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. # 100/100
  2.  
  3. coffee_list = input().split()
  4. n = int(input())
  5. count_of_commands = 0
  6. command_data = input()
  7.  
  8. while not count_of_commands == n:
  9.     command_data = command_data.split()
  10.     count_of_commands += 1
  11.  
  12.     if "Include" in command_data:
  13.         type_of_coffee = command_data[1]
  14.         coffee_list.append(type_of_coffee)
  15.  
  16.     elif "Remove" in command_data:
  17.         el_to_remove = command_data[1]
  18.         count_to_remove = int(command_data[2])
  19.         if el_to_remove == "first":
  20.             if len(coffee_list) < count_to_remove:
  21.                 continue
  22.             for i in range(count_to_remove):
  23.                 coffee_list.pop(0)
  24.         elif el_to_remove == "last":
  25.             if len(coffee_list) < count_to_remove:
  26.                 continue
  27.             for i in range(count_to_remove):
  28.                 coffee_list.pop(-1)
  29.  
  30.     elif "Prefer" in command_data:
  31.         index_1 = int(command_data[1])
  32.         index_2 = int(command_data[2])
  33.         if 0 < index_1 < len(coffee_list) and 0 < index_2 < len(coffee_list):
  34.             coffee_list[index_1], coffee_list[index_2] = coffee_list[index_2], coffee_list[index_1]
  35.         else:
  36.             continue
  37.  
  38.     elif "Reverse" in command_data:
  39.         coffee_list.reverse()
  40.     if count_of_commands == n:
  41.         break
  42.     command_data = input()
  43.    
  44. print("Coffees:")
  45. print(" ".join(coffee_list))
Advertisement
Add Comment
Please, Sign In to add comment