Pagini recente » Cod sursa (job #199870) | Cod sursa (job #2228744) | Cod sursa (job #1883695) | Cod sursa (job #2811989) | Cod sursa (job #2780180)
#include <bits/stdc++.h>
using namespace std;
ifstream f("bool.in");
ofstream g("bool.out");
char s[1005],v[105];
int n,i;
int termen();
int factor();
int calcul()
{
while(s[i]==' ')i++;
int x;
x=termen();
while(s[i]==' ')i++;
while(s[i]=='O' && s[i+1]=='R')
{
i+=2;
while(s[i]==' ')i++;
x|=termen();
while(s[i]==' ')i++;
}
return x;
}
int termen()
{
while(s[i]==' ')i++;
int x;
x=factor();
while(s[i]==' ')i++;
while(s[i]=='A' && s[i+1]=='N' && s[i+2]=='D')
{
i+=3;
while(s[i]==' ')i++;
x&=factor();
while(s[i]==' ')i++;
}
return x;
}
int factor()
{
int x;
while(s[i]==' ')i++;
if(s[i]=='(')
{
i++;
while(s[i]==' ')i++;
x=calcul();
while(s[i]==' ')i++;
i++;
}
else if(s[i]=='N' && s[i+1]=='O' && s[i+2]=='T')
{
i+=3;
while(s[i]==' ')i++;
x=1-factor();
while(s[i]==' ')i++;
}
else if(s[i]=='F' && s[i+1]=='A' && s[i+2]=='L' && s[i+3]=='S' && s[i+4]=='E')
{
i+=5;
while(s[i]==' ')i++;
x=0;
}
else if(s[i]=='T' && s[i+1]=='R' && s[i+2]=='U' && s[i+3]=='E')
{
i+=4;
while(s[i]==' ')i++;
x=1;
}
else
{
x=v[s[i]-'A'];
i++;
while(s[i]==' ')i++;
}
return x;
}
int main()
{
int sol;
char c;
f.getline(s,sizeof s);
f>>n;
for(int j=0;j<n;j++)
{
f>>c;
v[c-'A']=1-v[c-'A'];
i=0;
sol=calcul();
g<<sol;
}
return 0;
}