Advertisement
differen71

Bees

Jan 21st, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.59 KB | None | 0 0
  1. """4.   Honey
  2. We think the process of making honey is amazing! Let's learn more about how bees make honey.
  3. Worker-bees collect nectar. When a worker-bee has found enough nectar,
  4. she returns to the hive to drop off the load and pass the nectar
  5. to waiting bees so they can really start the honey-making process.
  6. You will receive 3 sequences:
  7. • a sequence of integers, representing working bees
  8. • a sequence of integers, representing nectar
  9. • a sequence of symbols – "+", "-", "*" or "/", representing the honey-making process.
  10. Your task is to check if the bee has collected enough nectar to return to the hive and keep track of the total honey
  11. waiting bees made with the collected nectar.
  12. Step one: check if a bee has collected enough nectar. You should take the first bee and try to
  13. match it with the last nectar:
  14. • If the nectar value is more or equal to the value of the bee, it is considered collected,
  15. and the bee returns to the hive to drop off the load (step two).
  16. • If the nectar value is less than the value of the bee,
  17. you should remove the nectar and try to match the bee with the next nectar's value until the bee collects enough nectar.
  18. Step two: When a bee successfully collects nectar, she returns to the hive, and you should calculate the honey made.
  19. Take the first symbol in the sequence of symbols ("+", "-", "*" or "/") and make the corresponding calculation:
  20. "{matched_bee} {symbol} {matched_nectar}"
  21. The result represents the honey that is made from the passed nectar.
  22. The calculation should always return the absolute value of the result. After the calculation, remove the bee,
  23. the nectar, and the symbol.
  24. Stop making honey when you are out of bees or nectar.
  25. Input
  26. • On the first line, you will be given the values of bees - integers, separated by a single space
  27. • On the second line, you will be given the nectar's values - integers, separated by a single space
  28. • On the third line, you will be given symbols - "+", "-", "*" or "/", separated by a single space
  29. Output
  30. • On the first line - print the total honey made:
  31. o   "Total honey made: {total honey}"
  32. • On the next two lines print the bees or the nectar that are left, if there are any, otherwise skip the line:
  33. o   "Bees left: {bee1}, {bee2}, … {beeN}"
  34. o   "Nectar left: {nectar1}, {nectar2}, … {nectarN}"
  35. Constraints
  36. • All the bee's values will be integers in the range [0, 150]
  37. • Nectar's values will be integers in the range [0, 150]
  38. • There always will be enough symbols in the sequence of symbols
  39. """
  40. from collections import deque
  41.  
  42.  
  43. def honey_making(bee, symbol, collected_nectar):
  44.     honey_made = 0
  45.  
  46.     if symbol == "+":
  47.         honey_made += bee + collected_nectar
  48.     elif symbol == '-':
  49.         honey_made += bee - collected_nectar
  50.     elif symbol == '*':
  51.         honey_made += bee * collected_nectar
  52.     elif symbol == '/':
  53.         honey_made += bee / collected_nectar
  54.  
  55.     return honey_made
  56.  
  57.  
  58. working_bees = deque(map(int, input().split()))
  59. nectar = deque(map(int, input().split()))
  60. process = deque(input().split())
  61. total_honey = 0
  62.  
  63. while working_bees and nectar:
  64.     first_bee = working_bees.popleft()
  65.     last_nectar = nectar.pop()
  66.  
  67.     if last_nectar < first_bee:
  68.         working_bees.appendleft(first_bee)
  69.         continue
  70.     else:
  71.         current_symbol = process.popleft()
  72.         total_honey += abs(honey_making(first_bee, current_symbol, last_nectar))
  73.  
  74. if total_honey:
  75.     print(f"Total honey made: {total_honey}")
  76. if working_bees:
  77.     print(f"Bees left: {', '.join(str(x) for x in working_bees)}")
  78. if nectar:
  79.     print(f"Nectar left: {', '.join(str(x) for x in nectar)}")
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement