Pagini recente » Cod sursa (job #2380767) | Cod sursa (job #1498523) | Cod sursa (job #2218835) | Cod sursa (job #3260344) | Cod sursa (job #3196654)
#include <fstream>
using namespace std;
ifstream cin("bool.in");
ofstream cout("bool.out");
int i,n,k;
bool val[30];
char s[1002],sir[1002],ch ;
bool ecuatie();
bool termen();
bool factor();
bool expresie(){
bool r=termen();
while(s[i]=='O'&&s[i+1]=='R'){
i+=2;
r=(r||termen());
}
return r;
}
bool termen(){
bool r=factor();
while(s[i]=='A'&&s[i+2]=='D'){
i+=3;
r=(r&&factor());
}
return r;
}
bool factor(){
bool r;
if(s[i]=='('){
i++;
r=expresie();
i++;
}else
if(s[i]=='T'&&s[i+3]=='E')
i+=4,r=1;
else
if(s[i]=='F'&&s[i+4]=='E')
i+=5,r=0;
else
if(s[i]=='N'&&s[i+2]=='T'){
i+=3;
r=1-factor();
}else
r=val[s[i]-'A'];
return r;
}
int main()
{
cin.getline(sir,1002);
for(i=0;sir[i]!=0;i++)
if(sir[i]!=' ')
s[k++]=sir[i];
for(i=0;i<30;i++)
val[i]=0;
cin>>n;
for(k=0;k<n;k++){
cin>>ch;
val[ch-'A']=1-val[ch-'A'];
i=0;
cout<<expresie();
}
return 0;
}