-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircuitmath.cpp
69 lines (64 loc) · 1.44 KB
/
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
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
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
char or_func(char a, char b) {
if (a == 'F' && b == 'F') {
return 'F';
}
return 'T';
}
char and_func(char a, char b) {
if (a == 'T' && b == 'T') {
return 'T';
}
return 'F';
}
char not_func(char a) {
if (a == 'F') {
return 'T';
}
return 'F';
}
int main() {
int n; cin >> n;
char value[n];
for (int i=0; i<n;i++) {
cin >> value[i];
}
char wc = cin.get();
string input;
getline(cin, input);
stack<char> stack1;
int counter = 0;
char x, y;
for (int i=0; i<input.length(); i++) {
char M = input[i];
switch (M) {
case ' ':
break;
case '+':
x = stack1.top(); stack1.pop();
y = stack1.top(); stack1.pop();
stack1.push(or_func(x,y));
break;
case '-':
x = stack1.top();
stack1.pop();
stack1.push(not_func(x));
break;
case '*':
x = stack1.top(); stack1.pop();
y = stack1.top(); stack1.pop();
stack1.push(and_func(x,y));
break;
default:
stack1.push(value[counter++]);
break;
}
}
cout << stack1.top();
return 0;
}