sibinasto

Problem 1 - Chocolate

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