-
Notifications
You must be signed in to change notification settings - Fork 0
/
circuitmath.cpp
42 lines (42 loc) · 1007 Bytes
/
circuitmath.cpp
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
// GitHub: EntityPlantt/Kattis
#include <iostream>
#include <vector>
using namespace std;
int n, arr[26], i;
bool b; char c;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> c;
if (c == 'T') arr[i] = true;
}
vector <bool> v;
while (cin >> c) {
switch (c) {
case '+':
b = v.back(); v.pop_back();
b |= v.back(); v.pop_back();
v.push_back(b);
break;
case '*':
b = v.back(); v.pop_back();
b &= v.back(); v.pop_back();
v.push_back(b);
break;
case '-':
b = !v.back(); v.pop_back();
v.push_back(b);
break;
default:
v.push_back(arr[c - 'A']);
break;
}
/*
cout << "Array now:";
for (i = 0; i < v.size(); i++) cout << (v[i] ? " T" : " F");
cout << '\n';
*/
}
cout << (v.back() ? 'T' : 'F');
return 0;
}