Advertisement
go6odn28

05. Santa's Present Factory

May 22nd, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.10 KB | None | 0 0
  1. # 1
  2. from collections import deque
  3.  
  4. materials = [int(x) for x in input().split()]
  5. magic_level = deque([int(x) for x in input().split()])
  6.  
  7. doll_magic_needed = 150
  8. wooden_train_magic_needed = 250
  9. teddy_bear_magic_needed = 300
  10. bicycle_magic_needed = 400
  11.  
  12. possible_toys = {"Doll": doll_magic_needed, "Wooden train": wooden_train_magic_needed,
  13.                  "Teddy bear": teddy_bear_magic_needed, "Bicycle": bicycle_magic_needed}
  14. created_toys = []
  15.  
  16.  
  17. def check_for_matches(sum_):
  18.     for key, value in possible_toys.items():
  19.         if value == sum_:
  20.             created_toys.append(key)
  21.  
  22.  
  23. while materials and magic_level:
  24.     material = materials.pop()
  25.     magic = magic_level.popleft()
  26.     total_magic = magic * material
  27.  
  28.     if total_magic in possible_toys.values():
  29.         check_for_matches(total_magic)
  30.  
  31.     else:
  32.         if total_magic < 0:
  33.             new_material = magic + material
  34.             materials.append(new_material)
  35.         elif total_magic > 0:
  36.             materials.append(material + 15)
  37.  
  38.         else:
  39.             if magic == 0 and material == 0:
  40.                 continue
  41.             elif magic == 0:
  42.                 materials.append(material)
  43.             else:
  44.                 magic_level.appendleft(magic)
  45.  
  46. if (("Teddy bear" in created_toys and "Bicycle" in created_toys)
  47.         or ("Doll" in created_toys and "Wooden train" in created_toys)):
  48.     print("The presents are crafted! Merry Christmas!")
  49. else:
  50.     print("No presents this Christmas!")
  51.  
  52. materials_left = ", ".join(str(x) for x in materials)
  53. magic_left = ", ".join(str(x) for x in magic_level)
  54.  
  55. if materials:
  56.     print(f"Materials left:", end=" ")
  57.     for i in range(len(materials) - 1, -1, -1):
  58.         if i == 0:
  59.             print(materials[i], end=" ")
  60.         else:
  61.             print(materials[i], end=", ")
  62.     print('')
  63. if magic_level:
  64.     print(f"Magic left:", end=" ")
  65.     for i in range(len(magic_level)):
  66.         if i == len(magic_level) - 1:
  67.             print(magic_level[i], end=" ")
  68.         else:
  69.             print(magic_level[i], end=", ")
  70.     print('')
  71.  
  72. sorted_created = sorted(set(created_toys))
  73.  
  74. for i in sorted_created:
  75.     print(f"{i}: {created_toys.count(i)}")
  76.  
  77.  
  78.  
  79. *2
  80. # 100/100
  81. # from collections import deque
  82. #
  83. # materials = [int(x) for x in input().split()]
  84. # magic_level = deque([int(x) for x in input().split()])
  85. #
  86. # doll_magic_needed = 150
  87. # wooden_train_magic_needed = 250
  88. # teddy_bear_magic_needed = 300
  89. # bicycle_magic_needed = 400
  90. #
  91. # possible_toys = {"Doll": doll_magic_needed, "Wooden train": wooden_train_magic_needed,
  92. #                  "Teddy bear": teddy_bear_magic_needed, "Bicycle": bicycle_magic_needed}
  93. # created_toys = []
  94. #
  95. #
  96. # def check_for_matches(sum_):
  97. #     for key, value in possible_toys.items():
  98. #         if value == sum_:
  99. #             created_toys.append(key)
  100. #
  101. #
  102. # while materials and magic_level:
  103. #     material = materials.pop()
  104. #     magic = magic_level.popleft()
  105. #     total_magic = magic * material
  106. #
  107. #     if total_magic in possible_toys.values():
  108. #         check_for_matches(total_magic)
  109. #
  110. #     else:
  111. #         if total_magic < 0:
  112. #             new_material = magic + material
  113. #             materials.append(new_material)
  114. #         elif total_magic > 0:
  115. #             materials.append(material + 15)
  116. #
  117. #         else:
  118. #             if magic == 0 and material == 0:
  119. #                 continue
  120. #             elif magic == 0:
  121. #                 materials.append(material)
  122. #             else:
  123. #                 magic_level.appendleft(magic)
  124. #
  125. # if (("Teddy bear" in created_toys and "Bicycle" in created_toys)
  126. #         or ("Doll" in created_toys and "Wooden train" in created_toys)):
  127. #     print("The presents are crafted! Merry Christmas!")
  128. # else:
  129. #     print("No presents this Christmas!")
  130. #
  131. #
  132. # if materials:
  133. #     materials = materials[::-1]
  134. #     print(f"Materials left: {', '.join(map(str, materials))}")
  135. #
  136. # if magic_level:
  137. #     print(f"Magic left: {', '.join(map(str, magic_level))}")
  138. #
  139. # sorted_created = sorted(set(created_toys))
  140. #
  141. # for i in sorted_created:
  142. #     print(f"{i}: {created_toys.count(i)}")
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement