Pagini recente » Cod sursa (job #391242) | Cod sursa (job #1787726) | Cod sursa (job #1936471) | Cod sursa (job #812526) | Cod sursa (job #407481)
Cod sursa(job #407481)
#include<stdio.h>
#include<string.h>
const char in[]="bool.in", out[]="bool.out";
const int N=1005;
bool lit[28];
char ch[N], x, *p;
int n, a(), b(), c();
int a()
{
int rez=b();
while(!strncmp(p, "OR", 2))p+=2, rez|=b();
return rez;
}
int b()
{
int rez=c();
while(!strncmp(p, "AND", 3))p+=3, rez&=c();
return rez;
}
int c()
{int rez;
if(*p==' ')++p;
if(*p=='(')++p, rez=a(), ++p;
if(!strncmp(p, "NOT", 3))p+=3, rez=!c();
else if(!strncmp(p, "FALSE", 5))rez=0, p+=5;
else if(!strncmp(p, "TRUE", 4))rez=1, p+=4;
else if(*p>='A' and *p<='Z')rez=lit[*p-'A'], p++;
return rez;
}
int main()
{
freopen(in,"r",stdin);
freopen(out,"w",stdout);
//fgets(ch, N, stdin);
gets(ch);
for(scanf("%d\n", &n);n;--n)
{
scanf("%c", &x);
lit[x-'A']^=1;
p=ch;
printf("%d", a());
}
return 0;
}