Pagini recente » Cod sursa (job #1290018) | Cod sursa (job #688736) | Cod sursa (job #252843) | Cod sursa (job #1383984) | Cod sursa (job #187987)
Cod sursa(job #187987)
#include<stdio.h>
#include<string.h>
char e[2000],c;
int n,lg,i,j,a[200];
int EvalExp();
int EvalTermen();
int EvalFactor();
inline int min(int,int);
inline int max(int,int);
int main()
{
freopen("bool.in","r",stdin);
freopen("bool.out","w",stdout);
i=0;
scanf("%c",&e[0]);
while (e[i]!='\n'){
i++;
scanf("%c",&e[i]);
if (e[i]==' ')
i--;
}
lg=i;
scanf("%d\n",&n);
for (i=1;i<=28;i++)
a[i]=0;
for (j=1;j<=n;j++)
{
scanf("%c",&c);
if (a[c-'A']==0) a[c-'A']=1;
else a[c-'A']=0;
i=0;
printf("%d",EvalExp());
}
printf("\n");
return 0;
}
int EvalExp()
{int r=EvalTermen();
while (e[i]=='O' && e[i+1]=='R')
{
i+=2;
r=max(r,EvalTermen());
}
return r;
}
int EvalTermen()
{int r=EvalFactor();
while (e[i]=='A' && a[i+1]=='N')
{
i+=3;
r=min(r,EvalFactor());
}
return r;
}
int EvalFactor()
{int f;
if (e[i]=='N' && e[i+1]=='O'){
i+=3;
f=1-EvalFactor();
}
else
if (e[i]=='('){
i++;
f=EvalExp();
i++;
}
else
if (e[i]=='T' && e[i+1]=='R'){
i+=4;
f=1;
}
else
if (e[i]=='F' && e[i+1]=='A'){
i+=5;
f=0;
}
else{
i++;
f=a[e[i-1]-'A'];
}
return f;
}
inline int min(int a, int b){
if (a<b)return a;
else return b;
}
inline int max(int a,int b){
if(a>b)return a;
else return b;
}