-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path04. Honey.py
83 lines (53 loc) · 1.86 KB
/
04. Honey.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from collections import deque
class Stack:
def __init__(self, items):
self.stack = list(items)
def push(self, element):
self.stack.append(element)
def pop(self):
return self.stack.pop()
def peek(self):
return self.stack[-1]
def count(self):
return len(self.stack)
def __repr__(self):
return ', '.join([str(item) for item in self.stack])
class MathOperations:
def __init__(self, bee, nectar):
self.bee = bee
self.nectar = nectar
def multiply(self):
return abs(self.bee * self.nectar)
def divide(self):
return abs(self.bee / self.nectar)
def add(self):
return abs(self.bee + self.nectar)
def subtract(self):
return abs(self.bee - self.nectar)
working_bees = deque(map(int, input().split()))
nectar = Stack(map(int, input().split()))
process = deque(input().split())
total_honey = 0
while working_bees and nectar.count():
current_bee = working_bees[0]
current_nectar = nectar.peek()
if current_bee <= current_nectar:
if process[0] == "*":
total_honey += MathOperations(current_bee, current_nectar).multiply()
elif process[0] == "/" and current_nectar > 0:
total_honey += MathOperations(current_bee, current_nectar).divide()
elif process[0] == "+":
total_honey += MathOperations(current_bee, current_nectar).add()
elif process[0] == "-":
total_honey += MathOperations(current_bee, current_nectar).subtract()
working_bees.popleft()
nectar.pop()
process.popleft()
elif current_bee > current_nectar:
nectar.pop()
continue
print(f"Total honey made: {total_honey}")
if working_bees:
print(f"Bees left: {', '.join([str(num) for num in working_bees])}")
if nectar.count():
print(f"Nectar left: {nectar}")