Pagini recente » Cod sursa (job #1033920) | Cod sursa (job #2709444) | Cod sursa (job #2864046) | Cod sursa (job #121832) | Cod sursa (job #2230163)
#include <fstream>
#include <cstring>
using namespace std;
ifstream in("bool.in");
ofstream out("bool.out");
char e[101],c,*p;
int n,v[26];
int OR(char *s);
int AND(char *s);
int verif(char *s);
int OR(char e[])
{ int t=AND(e);
while(*p=='O' && *(p+1)=='R')
{ p+=2;
t=t|AND(e);
}
return t;
}
int AND(char e[])
{ int t=verif(e);
while(*p=='A' && *(p+1)=='N')
{ p+=3;
t=t&verif(e);
}
return t;
}
int verif(char e[])
{ bool t,ok=0;
if(*p=='N' && *(p+1)=='O')
{ p+=3;
ok=1;
t=verif(e);
}
else if(*p=='(')
{ p++;
t=OR(e);
p++;
}
else if(*p=='T' && *(p+1) == 'R')
p+=4,t=1;
else if(*p=='F' && *(p+1)=='A')
p+=5,t=0;
else
t=v[*p-'A'],p++;
if(ok)
return 1-t;
return t;
}
void eliminare(char *s)
{ while(*s)
if(*s==' ')
strcpy(s,s+1);
else
s++;
}
int main()
{ in.getline(e,101);
in>>n;
in.get();
eliminare(e);
while(n--)
{ in.get(c);
v[c-'A']=1-v[c-'A'];
p=e;
out<<OR(e);
}
in.close();
out.close();
return 0;
}