Pagini recente » Cod sursa (job #627560) | Cod sursa (job #21925) | Cod sursa (job #3174585) | Cod sursa (job #1297818) | Cod sursa (job #1722889)
#include <fstream>
#include <iostream>
using namespace std;
char s[1005];
bool val[30];
int p;
bool getTerm();
bool getVal();
bool eval() {
bool term=getTerm();
while(s[p+1]=='O'&&s[p+2]=='R') {
p+=4;
term=getTerm()||term;
}
p++;
return term;
}
bool getTerm() {
bool term=getVal();
while(s[p+1]=='A'&&s[p+2]=='N') {
p+=5;
term=getVal()&&term;
}
return term;
}
bool getVal() {
if(s[p]>='A'&&s[p]<='Z') {
p++;
if(s[p]<'A'||s[p]>'Z')
return val[s[p-1]-'A'];
if(s[p-1]=='N'&&s[p]=='O') {
p+=3;
return !getVal();
}
if(s[p-1]=='T'&&s[p]=='R') {
p+=3;
return true;
}
if(s[p-1]=='F'&&s[p]=='A') {
p+=4;
return false;
}
}
else if(s[p]=='(') {
p++;
return eval();
}
}
int main()
{
ifstream fin("bool.in");
ofstream fout("bool.out");
fin.getline(s,1005);
int n;
fin>>n;
char c;
for(int i=1;i<=n;i++) {
fin>>c;
val[c-'A']=!val[c-'A'];
p=0;
fout<<eval();
}
return 0;
}