-
Notifications
You must be signed in to change notification settings - Fork 0
/
circuit_math.py
44 lines (30 loc) · 900 Bytes
/
circuit_math.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
from sys import stdin
import math
import queue
import heapq
letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ]
def main():
_ = input()
*truths, = input().split()
truth_map = {}
for i, truth in enumerate(truths):
bool = True if truth == 'T' else False
truth_map[letters[i]] = bool
*inpoo, = input().split()
stack = []
for i in inpoo:
if i == '*':
a = stack.pop()
b = stack.pop()
stack.append(a and b)
elif i == '+':
a = stack.pop()
b = stack.pop()
stack.append(a or b)
elif i == '-':
a = stack.pop()
stack.append(not a)
else:
stack.append(truth_map[i])
print('T' if stack[0] else 'F')
main()