Pagini recente » Cod sursa (job #2534372) | Cod sursa (job #219655) | Cod sursa (job #2034941) | Cod sursa (job #792233) | Cod sursa (job #1640057)
#include <fstream>
#include <string.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
char x[1005],y[10],f;
int i,n,j;
bool o[30];
bool sau();
bool si();
void stringget()
{
int k=0;
memset(y,0,strlen(y));
while(x[i]==' ')
i++;
while(x[i]>='A'&&x[i]<='Z')
{
y[k]=x[i];
k++;
i++;
}
if(x[i]==' ')
i++;
}
bool eval()
{
bool ok=sau();
while(strcmp(y,"OR")==0)
{
if(sau()||ok)
ok=1;
else
ok=0;
stringget();
}
return ok;
}
bool sau()
{
bool ok=si();
stringget();
while(strcmp(y,"AND")==0)
{
if(si()&&ok)
ok=1;
else
ok=0;
stringget();
}
return ok;
}
bool si()
{
bool ok;
if(x[i]=='(')
{
i++;
ok=eval();
i++;
}
else
{
stringget();
if(strcmp(y,"NOT")==0)
{
if(x[i]=='(')
{
i++;
ok=eval();
i++;
}
else
{
stringget();
if(strcmp(y,"TRUE")==0)
ok=1;
else
if(strcmp(y,"FALSE")==0)
ok=0;
else
ok=o[y[0]-'A'];
}
if(ok)
ok=0;
else
ok=1;
}
else
if(strcmp(y,"TRUE")==0)
ok=1;
else
if(strcmp(y,"FALSE")==0)
ok=0;
else
ok=o[y[0]-'A'];
}
return ok;
}
int main()
{
fin.getline(x,1005);
fin>>n;
fin.get();
for(j=1;j<=n;j++)
{
fin.get(f);
i=0;
if(o[f-'A']==0)
o[f-'A']=1;
else
o[f-'A']=0;
fout<<eval();
}
return 0;
}