Pagini recente » Cod sursa (job #1674985) | Cod sursa (job #1628073) | Cod sursa (job #2783054) | Cod sursa (job #964170) | Cod sursa (job #1710109)
#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] == '(') {
expr.push_back('(');
}
else 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 = '-';
else if (str == ")") str.pop_back();
expr += str + ')';
str.clear();
}
else if(ReadInput[i] == ' ' or i == ReadLast) {
if (i == ReadLast) str.push_back(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]);
}
}
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;
ans = 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;
}