Pagini recente » Cod sursa (job #1526246) | Cod sursa (job #3201842) | Cod sursa (job #771191) | Cod sursa (job #1748028) | Cod sursa (job #2109327)
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
char A[1005],c;
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 (a&&tot(++d));
if(b==5)
return (a||tot(++d));
}
}
int main()
{
fin>>A;
int h=0;
fout<<A;
ln=strlen(A);
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>c;
var[c]=!var[c];
cout<<var[c]<<" "<<!var[c];
h=1;
fout<<tot(h);
}
return 0;
}