Pagini recente » Cod sursa (job #473428) | Istoria paginii utilizator/adriandiaconita | Cod sursa (job #201255) | Cod sursa (job #1958085) | Cod sursa (job #1203698)
#include <cstdio>
#include <cstring>
using namespace std;
const int knmax = 2e3;
bool vals[300];
char *p, given_expr[knmax];
bool oring();
bool anding();
bool absolute();
bool oring(){
bool t = anding();
while(*p == ' ' && *(p + 1) == 'O' && *(p + 2) == 'R'){
p += 4;
t |= anding();
}
return t;
}
bool anding(){
bool t = absolute();
while(*p == ' ' && *(p + 1) == 'A' && *(p + 2) == 'N'){
p += 5;
t &= absolute();
}
return t;
}
bool absolute(){
bool t;
if(*p == 'N' && *(p + 1) == 'O'){
p += 4;
t = !(absolute());
}
else if(*p == 'F' && *(p + 1) == 'A'){
p += 5;
t = false;
}
else if(*p == 'T' && *(p + 1) == 'R'){
p += 4;
t = true;
}
else if(*p == '('){
++p;
t = oring();
++p;
}
else{
t = vals[(*p)];
p += 1;
}
return t;
}
char ans[knmax];
int main(){
freopen("bool.in", "r", stdin);
freopen("bool.out", "w", stdout);
gets(given_expr);
int n;
scanf("%d\n", &n);
for(int i = 0; i < n; ++i){
char x;
scanf("%c", &x);
vals[x] = !vals[x];
p = given_expr;
if(oring())
ans[i] = 1 + '0';
else
ans[i] = 0 + '0';
}
puts(ans);
return 0;
}