Pagini recente » Cod sursa (job #1317688) | Cod sursa (job #562369) | Cod sursa (job #377255) | Cod sursa (job #1872495) | Cod sursa (job #2693479)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
bool val[130];
string s, ins;
int pos, n;
void readInputAndCompress() {
getline(fin, ins);
for (int i = 0; i < ins.size(); ++i) {
if (ins.substr(i, 2) == "OR")
s += 'o', ++i;
else if (ins.substr(i, 3) == "NOT")
s += '!', i += 2;
else if (ins.substr(i, 3) == "AND")
s += 'a', i += 2;
else if (ins.substr(i, 4) == "TRUE")
s += '1', i += 3;
else if (ins.substr(i, 5) == "FALSE")
s += '0', i += 4;
else if (ins[i] != ' ')
s += ins[i];
}
n = s.size() - 1;
val['1'] = 1;
return;
}
// Aa((Bo!C)o((1)))
bool _and();
bool termen();
bool _or() {
bool rez = _and();
while (s[pos] == 'o')
rez |= _and();
return rez;
}
bool _and() {
bool rez = termen();
while (pos == 'a')
rez &= termen();
return rez;
}
bool termen() {
bool rez, _not = false;
while (s[pos] == '!')
_not = !_not, ++pos;
if (s[pos] == '(')
++pos, rez = _or();
else
rez = val[s[pos]];
++pos;
if (_not)
rez = !rez;
return rez;
}
int main() {
readInputAndCompress();
int q;
fin >> q;
while (q--) {
char el;
fin >> el;
val[el] = !val[el];
pos = 0;
fout << _or();
}
return 0;
}