Advertisement
Guest User

Untitled

a guest
Aug 18th, 2020
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. from collections import deque, defaultdict
  2.  
  3. materials = list(map(int, input().split()))
  4. magic = deque(map(int, input().split()))
  5.  
  6. presents = {
  7.     150: 'Doll',
  8.     250: 'Wooden train',
  9.     300: 'Teddy bear',
  10.     400: 'Bicycle',
  11. }
  12.  
  13. presents_crafted = defaultdict(int)
  14.  
  15. while materials and magic:
  16.     curr_material = materials.pop()
  17.     curr_magic = magic.popleft()
  18.     result = curr_material * curr_magic
  19.  
  20.     if result in presents:
  21.         presents_crafted[presents[result]] += 1
  22.         continue
  23.  
  24.     if result < 0:
  25.         materials.append(curr_material + curr_magic)
  26.     elif result > 0:
  27.         materials.append(curr_material + 15)
  28.     elif result == 0:
  29.         if curr_material != 0:
  30.             materials.append(curr_material)
  31.         elif curr_magic != 0:
  32.             magic.appendleft(curr_magic)
  33.  
  34. if 'Doll' in presents_crafted and 'Wooden train' in presents_crafted:
  35.     print('The presents are crafted! Merry Christmas!')
  36. elif 'Teddy bear' in presents_crafted and 'Bicycle' in presents_crafted:
  37.     print('The presents are crafted! Merry Christmas!')
  38. else:
  39.     print('No presents this Christmas!')
  40. if materials:
  41.     print(f'Materials left: {", ".join(str(i) for i in reversed(materials))}')
  42. if magic:
  43.     print(f'Magic left: {", ".join(str(i) for i in magic)}')
  44.  
  45. [print(f'{key}: {value}') for key, value in sorted(presents_crafted.items())]
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement