Pagini recente » Cod sursa (job #159355) | Cod sursa (job #2184285) | Cod sursa (job #2153386) | Cod sursa (job #900984) | Cod sursa (job #1028504)
#include <fstream>
using namespace std;
ifstream fin ("bool.in");
ofstream fout ("bool.out");
char c[1020],s[1020],m[110],*p;
int i,k,n,j;
int v[200];
int termen1 ();
int termen2 ();
int termen3 ();
int termen4 ();
int termen1 () {
int r=termen2 ();
while (*p=='|') {
p++;
r |= termen2();
}
return r;
}
int termen2 () {
int r=termen3 ();
while (*p=='&') {
p++;
r &= termen3();
}
return r;
}
int termen3 () {
int r=termen4();
if (*p=='!') {
p++;
//r=termen4();
if (r!=2)
r=(!termen4());
else
r=(!termen3());
}
return r;
}
int termen4 () {
int r;
if (*p=='(') {
p++;
r=termen1();
p++;
}else {
if (*p>='A' && *p<='Z' ) {
r=v[*p-'A'];
p++;
}else {
r=*p-'0';
p++;
}
}
return r;
}
int main () {
fin.get (s,1000);
fin.get ();
while (s[i]=='('){
c[++k]='(';
i++;
}
for (;s[i]!=0;i++) {
if (((s[i]>='A'&&s[i]<='Z'))&& !(s[i+1]>='A'&&s[i+1]<='Z')){
c[++k]=s[i];
}else
if (s[i]=='N'){
c[++k]='2';
c[++k]='!';
i+=3;
}else
if (s[i]=='T'){
c[++k]='1';
i+=3;
}else
if (s[i]=='F'){
c[++k]='0';
i+=3;
}else
if (s[i]=='('){
c[++k]='(';
}else
if (s[i]==')')
c[++k]=')';
else
if (s[i]=='O'){
c[++k]='|';
i+=2;
}else {
if (s[i]=='A'){
c[++k]='&';
i+=3;
}
}
}
fin>>n;
fin>>m;
//fout<<c+1<<"\n";
for (j=0;j<n;j++) {
v[m[j]-'A']=(v[m[j]-'A']^1);
p=c+1;
fout<<termen1();
}
return 0;
}