Advertisement
go6odn28

milkshakes_4

May 20th, 2024
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. from collections import deque
  2.  
  3. chocolates = deque([int(x) for x in input().split(", ")])
  4. cups_of_milk = deque([int(x) for x in input().split(', ')])
  5.  
  6. chocolate_milks_prepred = 0
  7.  
  8. while chocolates and cups_of_milk:
  9.     if chocolate_milks_prepred == 5:
  10.         break
  11.     current_cup_milk = cups_of_milk[0]
  12.     current_chcolate = chocolates[-1]
  13.  
  14.     if current_chcolate <= 0 and current_cup_milk <= 0:
  15.         cups_of_milk.popleft()
  16.         chocolates.pop()
  17.         continue
  18.  
  19.     if current_chcolate <= 0:
  20.         chocolates.pop()
  21.         continue
  22.     if current_cup_milk <= 0:
  23.         cups_of_milk.popleft()
  24.         continue
  25.     if current_chcolate == current_cup_milk:
  26.         chocolate_milks_prepred += 1
  27.         chocolates.pop()
  28.         cups_of_milk.popleft()
  29.     else:
  30.         cups_of_milk.rotate(-1)
  31.         chocolates[-1] -= 5
  32.  
  33. if chocolate_milks_prepred >= 5:
  34.     print(f"Great! You made all the chocolate milkshakes needed!")
  35. else:
  36.     print("Not enough milkshakes.")
  37.  
  38. if chocolates:
  39.     print(f"Chocolate: {', '.join(str(x) for x in chocolates)}")
  40. else:
  41.     print("Chocolate: empty")
  42.  
  43. if cups_of_milk:
  44.     print(f"Milk: {', '.join(str(x) for x in cups_of_milk)}")
  45. else:
  46.     print("Milk: empty")
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement