Pagini recente » Cod sursa (job #489302) | Cod sursa (job #265428) | Cod sursa (job #105733) | Cod sursa (job #1298014) | Cod sursa (job #2109761)
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
char A[1005],c,B[1005];
int var[100],ln,n;
int ce(int &d)
{
int termen(int &z);
if(A[d]=='A'&&A[d+1]=='N')
{d+=3;return 4;}
if(A[d]=='O'&&A[d+1]=='R')
{d+=2;return 5;}
if(A[d]=='N'&&A[d+1]=='O')
{d+=3;return !ce(++d);}
return termen(d);
}
int termen(int &d)
{
int tot(int &z);
if(A[d]=='T'&&A[d+1]=='R')
{
d+=4;
return 1;
}
if(A[d]=='F'&&A[d+1]=='A')
{
d+=5;
return 0;
}
if(A[d]=='(')
{
int r=tot(++d);
d++;
return r;
}
d+=1;
return var[A[d-1]];
}
int tot(int &d)
{
int a=ce(d);
int r=a;d++;///spatiul
while(d<=ln)
{
int b=ce(d);
if(b==4)
return (r&&tot(++d));
if(b==5)
return (r||tot(++d));
}
}
int main()
{
fin>>A;
while(1)
{
fin>>B;
if(47<B[0]&&B[0]<58)
break;
strcat(A," ");
strcat(A,B);
}
n=0;
int nb=strlen(B);
int h=0;
while(h<nb)
{
n=n*10+B[h]-'0';
h++;
}
ln=strlen(A);
for(int i=1;i<=n;i++)
{
fin>>c;
var[c]=!var[c];
h=0;
fout<<tot(h);
}
return 0;
}