Advertisement
vesso8

Milkshakes

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