Pagini recente » Cod sursa (job #1313102) | Cod sursa (job #2662322) | Cod sursa (job #569903) | Cod sursa (job #2554886) | Cod sursa (job #1710104)
#include <fstream>
#include <cstring>
using namespace std;
FILE *Input = fopen("bool.in", "r");
ifstream cin("bool.in");
ofstream cout("bool.out");
const int MaxLg = 1005;
string expr, upd;
bool val[30];
int n, ExprLast, pos;
char blank;
void ExprInit() {
string str, ReadInput;
getline(cin, ReadInput);
int ReadLast = ReadInput.size() - 1;
for (int i = 0; i <= ReadLast; ++i) {
if(ReadInput[i] == ' ') {
if (str == "OR") str = '|';
else if (str == "AND") str = '&';
else if (str == "NOT") str = '!';
else if (str == "TRUE") str = '+';
else if (str == "FALSE") str = '-';
expr += str;
str.clear();
}
else {
str.push_back(ReadInput[i]);
}
}
expr += str;
ExprLast = expr.size() - 1;
}
bool Prio2();
bool Prio3();
bool Prio1() {
bool ans;
char it = expr[pos];
if (it >= 'A' and it <= 'Z') {
++pos;
ans = val[it - 'A'];
}
else if (it == '+') {
++pos;
ans = true;
}
else if (it == '-') {
++pos;
ans = false;
}
else if (it == '!') {
++pos;
ans = !Prio1();
}
else if (it == '(') {
++pos;
Prio3();
++pos;
}
return ans;
}
bool Prio2() {
bool ans = Prio1();
while(expr[pos] == '&') {
++pos;
ans &= Prio1();
}
return ans;
}
bool Prio3() {
bool ans = Prio2();
while (expr[pos] == '|') {
++pos;
ans |= Prio2();
}
return ans;
}
int main() {
ExprInit();
cin >> n >> upd;
for (auto it: upd) {
val[it - 'A'] = !val[it - 'A'];
pos = 0;
cout << Prio3();
}
return 0;
}