Pagini recente » Cod sursa (job #2420658) | Cod sursa (job #2335025) | Cod sursa (job #1496207) | Cod sursa (job #587833) | Cod sursa (job #195375)
Cod sursa(job #195375)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 1005
int n,k,m;
char s[N],t[N];
int v[N];
inline int shas(char ch){
return (ch>='A' && ch<='Z');
}
void crisis(){
int k=0,x=strlen(s);
m=0;
while (k<x)
if (shas(s[k])){
if (!shas(s[k+1]))
t[++m]=s[k++];
else{
switch(s[k]){
case 'A':t[++m]='&';k+=3;break;
case 'F':t[++m]='0';k+=5;break;
case 'N':t[++m]='!';k+=3;break;
case 'O':t[++m]='|';k+=2;break;
case 'T':t[++m]='1';k+=4;break;
}
}
}
else
if (s[k]=='(' || s[k]==')')
t[++m]=s[k++];
else ++k;
}
int term();
int fact();
int solv(){
int aux=term();
while (t[k]=='|' && k<=m){
k++;
aux|=term();
}
return aux;
}
int term(){
int aux=fact();
while (t[k]=='&' && k<=m){
k++;
aux&=fact();
}
return aux;
}
int fact(){
int aux;
if (t[k]=='1' || t[k]=='0'){
if (t[k]=='0')
aux=0;
else
aux=1;
k++;
}
else
if (t[k]=='('){
k++;
aux=solv();
k++;
}
else
if (shas(t[k])){
aux=v[t[k]];
k++;
}
else
if (t[k]=='!'){
k++;
aux=!fact();
}
return aux;
}
int main(){
char ch;
freopen("bool.in","r",stdin);
freopen("bool.out","w",stdout);
gets(s);
crisis();
scanf("%d\n",&n);
memset(v,0,sizeof(v));
while (n--){
scanf("%c",&ch);
v[ch]=1-v[ch];
k=1;
printf("%d",solv()>0?1:0);
}
fclose(stdin);
fclose(stdout);
return 0;
}