# Cod sursa(job #2436985)

Utilizator Data 7 iulie 2019 21:07:12 Bool 100 cpp-64 done Arhiva de probleme 1.29 kb
``````#include <bits/stdc++.h>

using namespace std;

ifstream fin("bool.in");
ofstream fout("bool.out");

const int NMAX = 105;
const int LMAX = 1005;

char a[LMAX],v[NMAX];
int val[30],p,n;

bool Or();
bool And();
bool Nr();

bool Or()
{
bool r=And();
while(a[p]=='O' and a[p+1]=='R')
{
p+=3;
r|=And();
}
return r;
}

bool And()
{
bool r=Nr();
while(a[p]=='A' and a[p+1]=='N' and a[p+2]=='D')
{
p+=4;
r&=Nr();
}
return r;
}

bool Nr()
{
bool r=0;
if(a[p]=='(')
{
p++;
r=Or();
p++;
}
else if(a[p]=='N' and a[p+1]=='O' and a[p+2]=='T')
{
p+=4;
r=!Nr();
}
else if(a[p]=='T' and a[p+1]=='R' and a[p+2]=='U' and a[p+3]=='E')
{
p+=5;
r=1;
}
else if(a[p]=='F' and a[p+1]=='A' and a[p+2]=='L' and a[p+3]=='S' and a[p+4]=='E')
{
p+=6;
r=0;
}
else
{
r=val[a[p]-'A'];
p+=2;
}
return r;
}

int main()
{
fin.get(a,LMAX);
fin >> n;
fin.get();
fin.get(v,NMAX);
int nr=strlen(v);
for(int i=0;i<nr;i++)
{
val[v[i]-'A']=1-val[v[i]-'A'];
p=0;
fout << Or();
}
return 0;
}
``````