Pagini recente » Cod sursa (job #3235517) | Cod sursa (job #2641735) | Cod sursa (job #3234642) | Cod sursa (job #311579) | Cod sursa (job #1116471)
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 1002
char s[MAX] , c;
int N , i;
bool u['Z'+1];
bool eval();
bool t();
bool f();
int main()
{
freopen("bool.in" , "r" , stdin );
freopen("bool.out" , "w" , stdout );
gets(s);
int l = strlen(s)-1;
for(int j = 0 ; j <= l ; ++j )
if(s[j] == ' ')
strcpy(s+j,s+j+1),l--;
scanf("%d\n" , &N );
for(int j = 1 ; j <= N ; ++j )
{
i = 0;
scanf("%c" , &c);
u[(int)c] = 1-u[(int)c];
printf("%d" , eval());
}
return 0;
}
bool eval()
{
bool rez = t();
while(strncmp(s+i,"OR",2) == 0)
i+=2,rez |= t();
return rez;
}
bool t()
{
bool rez = f();
while(strncmp(s+i,"AND",3) == 0)
i+=3,rez&=f();
return rez;
}
bool f()
{
bool rez;
if(strncmp(s+i,"TRUE",4) == 0)
{i+=4;return 1;}
if(strncmp(s+i,"FALSE",5) == 0)
{i+=5;return 0;}
if(s[i] =='(')i++,rez = eval() , i++;
else
if(strncmp(s+i,"NOT",3) == 0){
i+=3;
rez = f();
rez = !rez;}
else
rez = u[(int)s[i]],i++;
return rez;
}