Pagini recente » Cod sursa (job #1286400) | Cod sursa (job #3198148) | Cod sursa (job #1596499) | Cod sursa (job #2060058) | Cod sursa (job #3155380)
#include <bits/stdc++.h>
using namespace std;
string s;
ifstream fin("bool.in");
ofstream fout("bool.out");
bool factor(), enot(), eand(), eor();
map<char, bool> val;
bool evaluare() {
bool r = eand();
if (s[0] == ' ')
s.erase(0, 1);
while (s.starts_with("OR")) {
s.erase(0, 2);
r = r | eand();
}
return r;
}
bool eand() {
bool r = enot();
if (s[0] == ' ')
s.erase(0, 1);
while (s.starts_with("AND")) {
s.erase(0, 3);
r = r & eand();
}
return r;
}
bool enot() {
bool r;
if (s[0] == ' ')
s.erase(0, 1);
if (s.starts_with("NOT"))
while (s.starts_with("NOT")) {
s.erase(0, 3);
r = !enot();
}
else
r = factor();
return r;
}
bool factor() {
bool r;
if (s[0] == ' ')
s.erase(0, 1);
if (s[0] == '(') {
s.erase(0, 1);
r = evaluare();
s.erase(0, 1);
} else if (s.starts_with("TRUE")) {
s.erase(0, 4);
r = true;
} else if (s.starts_with("FALSE")) {
s.erase(0, 5);
r = false;
} else {
r = val[s[0]];
s.erase(0, 1);
}
return r;
}
int main() {
string nou;
getline(fin, nou);
int n;
fin >> n;
string modificari;
fin >> modificari;
for (int i = 0; i < n; i++) {
val[modificari[i]] = !val[modificari[i]];
s = nou;
fout << evaluare();
}
}