Pagini recente » Cod sursa (job #1033510) | Cod sursa (job #695179) | Cod sursa (job #1824523) | Cod sursa (job #3139955) | Cod sursa (job #2453626)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1010;
int N, posMax;
int valch[30];
char s[NMAX], v[105];
bool OR();
bool AND();
bool NR();
bool OR(){
bool ans = AND();
while(s[posMax] == 'O' && s[posMax + 1] == 'R'){
posMax += 3;
ans = (ans|AND());
}
return ans;
}
bool AND(){
bool ans = NR();
while(s[posMax] == 'A' && s[posMax + 1] == 'N'){
posMax += 4;
ans = (ans&NR());
}
return ans;
}
bool NR(){
bool ans = 0;
if(s[posMax] == '('){
posMax++;
ans = OR();
posMax++;
} else if(s[posMax] == 'N' && s[posMax + 1] == 'O'){
posMax += 4;
ans = !NR();
} else if(s[posMax] == 'T' && s[posMax + 1] == 'R'){
posMax += 5;
ans = 1;
} else if(s[posMax] == 'F' && s[posMax + 1] == 'A'){
posMax += 6;
ans = 0;
} else {
ans = valch[v[posMax] - 'A'];
posMax += 2;
}
return ans;
}
int main(){
freopen("bool.in", "r", stdin);
freopen("bool.out", "w", stdout);
cin.get(s, NMAX);
scanf("%d ", &N);
cin.get(v, 105);
for(int i = 0; i < N; i++){
valch[v[i] - 'A'] = 1 - valch[v[i] - 'A'];
posMax = 0;
printf("%d", OR());
}
return 0;
}