Pagini recente » Cod sursa (job #486496) | Cod sursa (job #964008) | Cod sursa (job #127674) | Cod sursa (job #431966) | Cod sursa (job #1706233)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
int n,i;
char x[1005],ch,*p;
bool v[27],evaluare();
bool termen(){
bool b=0;
if(*p=='(')p++,b=evaluare(),p++;
else if(*p=='F'&&*(p+1)=='A'){p+=6,b=0;}
else if(*p=='T'&&*(p+1)=='R'){p+=5,b=1;}
else if(*p=='N'&&*(p+1)=='O'){p+=4,b=!termen();}
else {b=v[*p-'A'];p+=2;}
return b;
}
bool factor(){
bool b=termen();
while(*p=='A'&&*(p+1)=='N'){p+=4,b=b&termen();}
return b;
}
bool evaluare(){
bool b=factor();
while(*p=='O'&&*(p+1)=='R'){p+=3,b=b|factor();}
return b;
}
int main(){
fin.getline(x,1005);
fin>>n;
for(i=1; i<=n; i++){
fin>>ch;
if(v[ch-'A']=!v[ch-'A']){p=x;}
fout<<evaluare();
}
return 0;
}