Pagini recente » Cod sursa (job #1224775) | Cod sursa (job #2629713) | Cod sursa (job #2910364) | Cod sursa (job #2056689) | Cod sursa (job #3258300)
#include <fstream>
using namespace std;
ifstream cin("bool.in");
ofstream cout("bool.out");
int n,a[30],p;
char s[1000],c;
int expr();int termen();int factor();
int factor()
{ int f,ok=1;
if(s[p]=='N' && s[p+1]=='O')
{ p+=3;
ok=1-ok;
f=factor();
}
else
{ if(s[p]=='('){p++;f=expr();p++;}
else
{ if(s[p]=='T' && s[p+1]=='R')
{ p=p+4;
f=1;
}
else if(s[p]=='F' && s[p+1]=='A')
{ p=p+5;
f=0;
}
else
{ f=a[s[p]-'A'];
p++;
}
}
}
if(ok)return f;
else return 1-f;
}
int termen()
{ int t=factor();
while(s[p]=='A' && s[p]=='N')
{ p=p+3;
t=t&factor();
}
return t;
}
int expr()
{
int e=termen();
while(s[p]=='O' && s[p+1]=='R')
{ p+=2;
e=e|termen();
}
return e;
}
int main()
{ cin.getline(s,1001);
cin>>n;
int j=0;
for(int i=0;s[i];++i)if(s[i]!=' ')s[j++]=s[i];
s[j]=NULL;
for(int i=1;i<=n;i++)
{ cin>>c;
a[c-'A']=1-a[c-'A'];
p=0;
cout<<expr();
}
cout<<'\n';
return 0;
}