Pagini recente » Cod sursa (job #2299819) | Cod sursa (job #2694115) | Cod sursa (job #2672134) | Cod sursa (job #2212088) | Cod sursa (job #3251890)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
bool nu();
bool si();
bool sau();
bool fact();
void debut();
int i,n,par,lg,lg2;
char s[1500],c[1500],l[1000];
unordered_map <int,bool> v;
int main()
{
fin.getline(s,1400);
lg=strlen(s);
debut();
lg=lg2;
lg--;
fin>>n;
for(i=1;i<=n;i++)
{fin>>l[i];v[(int)l[i]]=0;}
for(par=1;par<=n;par++)
{
i=0;
v[(int)l[par]]=1-v[(int)l[par]];
fout<<sau();
}
return 0;
}
void debut()
{
for(i=0;i<lg;i++)
{
if(s[i]=='A'&&s[i+1]=='N'&&s[i+2]=='D')
c[lg2++]='&',i+=2;
else if(s[i]=='N'&&s[i+1]=='O'&&s[i+2]=='T')
c[lg2++]='!',i+=2;
else if(s[i]=='O'&&s[i+1]=='R')
c[lg2++]='|',i++;
else if(s[i]=='T'&&s[i+1]=='R'&&s[i+2]=='U'&&s[i+3]=='E')
c[lg2++]='1',i+=3;
else if(s[i]=='F'&&s[i+1]=='A'&&s[i+2]=='L'&&s[i+3]=='S'&&s[i+4]=='E')
c[lg2++]='0',i+=4;
else if(s[i]!=' ')c[lg2++]=s[i];
}
}
bool sau()
{
bool x=si();
while(i<lg&&c[i]=='|')
{
i++;
x|=si();
}
return x;
}
bool si()
{
bool x=nu();
while(i<lg&&c[i]=='&')
{
i++;
x&=nu();
}
return x;
}
bool nu()
{
if(c[i]=='!')
{
while(i<lg&&c[i]=='!')
{
i++;
return 1-nu();
}
}
else return fact();
}
bool fact()
{
bool x=0;
if(c[i]=='(')
{
i++;
x=sau();
i++;
}
else
{
if(isdigit(c[i]))x=c[i]-'0';
else if(c[i]>='A'&&c[i]<='Z')x=v[(int)c[i]];
i++;
}
return x;
}