Advertisement
Guest User

Untitled

a guest
Oct 7th, 2023
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. from collections import deque
  2.  
  3. presents = {
  4.     150: 'Doll',
  5.     250: 'Wooden train',
  6.     300: 'Teddy bear',
  7.     400: 'Bicycle'
  8. }
  9.  
  10. materials = [int(x) for x in input().split()]
  11. magic_values = deque(int(x) for x in input().split())
  12. crafted_presents = dict()
  13.  
  14. while True:
  15.     if not materials or not magic_values:
  16.         break
  17.  
  18.     current_material = materials.pop()
  19.     current_magic = magic_values.popleft()
  20.     total_magic = current_material * current_magic
  21.  
  22.     if total_magic in presents.keys():
  23.         if presents[total_magic] not in crafted_presents.keys():
  24.             crafted_presents[presents[total_magic]] = 1
  25.             continue
  26.         crafted_presents[presents[total_magic]] += 1
  27.         continue
  28.  
  29.     if total_magic < 0:
  30.         materials.append(current_material + current_magic)
  31.  
  32.     elif total_magic > 0:
  33.         current_material += 15
  34.         materials.append(current_material)
  35.  
  36.     elif total_magic == 0:
  37.         if current_material != 0:
  38.             materials.append(current_material)
  39.         if current_magic != 0:
  40.             magic_values.appendleft(current_magic)
  41.  
  42. if ('Doll' in crafted_presents and 'Wooden train' in crafted_presents) or \
  43.         ('Teddy bear' in crafted_presents and 'Bicycle' in crafted_presents):
  44.     print('The presents are crafted! Merry Christmas!')
  45. else:
  46.     print('No presents this Christmas!')
  47.  
  48. if materials:
  49.     print(f"Materials left: {', '.join(str(x) for x in materials[::-1])}")
  50. if magic_values:
  51.     print(f"Magic left: {', '.join(str(x) for x in magic_values)}")
  52.  
  53. for key, value in sorted(crafted_presents.items(), key=lambda x: x[0]):
  54.     print(f"{key}: {value}")
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement