Pagini recente » Cod sursa (job #188268) | Cod sursa (job #2622457) | Cod sursa (job #558084) | Cod sursa (job #2668020) | Cod sursa (job #1545303)
#include <stdio.h>
#include <cstring>
#define nmax 1010
using namespace std;
int m,n,i,j;
bool val[300]; char c,s[nmax];
bool eval();
bool termen();
bool factor();
bool eval()
{
bool x=termen();
while (s[j]=='O' && s[j+1]=='R') {
j+=2; x=x|termen();
}
return x;
}
bool termen()
{
bool x=factor();
while (s[j]=='A' && s[j+1]=='N' && s[j+2]=='D') {
j+=3; x=x&factor();
}
return x;
}
bool factor()
{
bool x;
if (s[j]==' ') j++,x=eval();
if (s[j]=='(') {
j++; x=eval(); j++;
} else {
bool ok=true;
if (s[j]=='T' && s[j+1]=='R') {
j+=5; return 1;
}
if (s[j]=='F' && s[j+1]=='A') {
j+=6; return 0;
}
while (s[j]=='N' && s[j+1]=='O' && s[j+2]=='T') {
j+=3; ok=false;
}
if (s[j]>='A' && s[j]<='Z') {
if (!ok) x=!val[s[j]]; else
x=val[s[j]];
j++;
}
}
return x;
}
int main() {
freopen("bool.in","r",stdin);
freopen("bool.out","w",stdout);
gets(s+1); n=strlen(s+1);
scanf("%d\n",&m);
for (i=1;i<=m;i++) {
scanf("%c",&c); val[c]=1-val[c]; j=1;
printf("%d",eval());
}
return 0;
}