Pagini recente » Cod sursa (job #697104) | Cod sursa (job #880677) | Cod sursa (job #835703) | Cod sursa (job #72409) | Cod sursa (job #427508)
Cod sursa(job #427508)
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n;
char exp[1024];
int val[56];
int eval(int a, int b) {
//2 parti
int p = 0;
int rez = -1;
for (int i = b; i >= a; --i) {
if (exp[i] == '(') {p++;continue;}
if (exp[i] == ')') {p--;continue;}
if (exp[i] == ' ') continue;
if (p == 0 && exp[i] == 'O' && (i + 1 <= b && exp[i+1] == 'R'))
return eval(a, i - 2) || eval(i+3, b);
if (p == 0 && exp[i] == 'A' && (i+1 <= b && exp[i+1] == 'N'))
return eval(a, i - 2) && eval(i+4, b);
}
if (exp[a] == '(') return eval(a+1, b-1);
if (exp[a] == 'T' && (a+1 <= b && exp[a+1] =='R')) return 1;
if (exp[a] == 'F' && (a+1 <= b && exp[a+1] == 'A')) return 0;
if (exp[a] == 'N' && (a+1 <= b && exp[a+1] == 'O')) return !eval(a+4, b);
return val[exp[a]-'A'];
}
int main() {
freopen("bool.in", "r", stdin);
freopen("bool.out", "w", stdout);
cin.getline(exp, 1024);
n = strlen(exp);
int m;
scanf("%d\n", &m);
while (m--) {
char c; cin >> c;
val[c-'A'] ^= 1;
printf("%d", eval(0, n - 1));
}
printf("\n");
return 0;
}