Pagini recente » Diferente pentru runda/creangar intre reviziile 5 si 7 | Diferente pentru preoni-2005/runda-1/solutii intre reviziile 33 si 8 | Monitorul de evaluare | Diferente pentru summer-challenge-2007/solutii/runda-2 intre reviziile 25 si 6 | Cod sursa (job #1639968)
#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(ok||sau())
ok=1;
else
ok=0;
stringget();
}
return ok;
}
bool sau()
{
bool ok=si();
while(strcmp(y,"AND")==0)
{
if(ok&&si())
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]=='(')
ok=eval();
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;
}