Pagini recente » Cod sursa (job #471497) | Cod sursa (job #1580925) | Cod sursa (job #711856) | Cod sursa (job #2793313) | Cod sursa (job #1520098)
#include <cstdio>
using namespace std;
char s[100000];
bool nr[26];
int index, n;
bool doi();
bool unu(){
int r;
if( s[index]=='!' ){++index;r=!doi();}
else r=doi();
if( s[index]=='&' || s[index]=='|' ){
if( s[index+1]=='!' )
if( s[index++]=='&' ) r&=(!doi());
else r|=(!doi());
else
if( s[index++]=='&' ) r&=doi();
else r|=doi();
}
return r;
}
bool doi(){
if( s[index]=='(' ){
++index;
int r=unu();
++index;
return r;
}
return nr[s[index++]-'A'];
}
int main()
{
freopen( "bool.in", "r", stdin );
freopen( "bool.out", "w", stdout );
fgets( s, 100000, stdin );
int i, j=0;
for( i=0; s[i]!='\n'; ++i){
if( s[i]==' ' )continue;
if( s[i]=='A' && s[i+1]=='N' ){s[j++]='&';i+=2;continue;}
if( s[i]=='O' && s[i+1]=='R' ){s[j++]='|';++i;continue;}
if( s[i]=='T' && s[i+1]=='R' ){s[j++]='1';i+=3;continue;}
if( s[i]=='F' && s[i+1]=='A' ){s[j++]='0';i+=4;continue;}
if( s[i]=='N' && s[i+1]=='O' ){s[j++]='!';i+=2;continue;}
s[j++]=s[i];
}
s[j]='\0';
n=j;
char x;
int a;
scanf( "%d\n", &a );
for( i=0; i<a; ++i ){
scanf( "%c", &x );
nr[x-'A']=!nr[x-'A'];
index=0;
printf( "%d", unu() );
}
return 0;
}