Pagini recente » Cod sursa (job #920118) | Istoria paginii utilizator/arina.popianu | Cod sursa (job #141691) | Cod sursa (job #2098575) | Cod sursa (job #407459)
Cod sursa(job #407459)
#include<stdio.h>
#include<string.h>
const char in[]="bool.in", out[]="bool.out";
const int N=1000;
bool lit[28];
char ch[N], x, *p;
int n, a(), b(), c();
int a()
{
int rez=b();
while(!strncmp(p, "OR", 2))p+=3, 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, 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+=2;
return rez;
}
int main()
{
freopen(in,"r",stdin);
freopen(out,"w",stdout);
fgets(ch, N, stdin);
for(scanf("%d\n", &n);n;--n)
{
scanf("%c", &x);
lit[x-'A']^=1;
p=ch;
printf("%d", a());
}
return 0;
}