Pagini recente » Cod sursa (job #1927431) | Cod sursa (job #2681312) | Cod sursa (job #2184508) | Cod sursa (job #509856) | Cod sursa (job #1780294)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("bool.in");
ofstream out ("bool.out");
char s[1050];
char notf[4] = {'N','O','T'};
char andf[4]= {'A','N','D'};
char orf[4]= {'O','R'};
char truf[7]= {'T','R','U','E'};
char falsf[7]= {'F','A','L','S','E'};
int poz;
bool val[35];
int crt();
bool expresie();
bool termen();
bool si(bool a,bool b)
{
if(a==1 && b==1)
return 1;
else
return 0;
}
bool sau(bool a,bool b)
{
if(a==1 || b==1)
return 1;
else
return 0;
}
bool fnot()
{
int i;
bool ok=1;
for(i=0; i<=2; i++)
if(s[i+poz]!=notf[i])
ok=0;
if(ok==1)
{
poz+=4;
return 1;
}
else
return 0;
}
int crtop()
{
int i;
bool ok=1;
if(fnot()==1)
return !crtop();
for(i=0; i<=2; i++)
if(s[i+poz]!=andf[i])
ok=0;
if(ok==1)
return 2;
ok=1;
for(i=0; i<=1; i++)
if(s[i+poz]!=orf[i])
ok=0;
if(ok==1)
return 3;
return 5;
}
int crtval()
{
int ok=1,i;
for(i=0; i<=3; i++)
if(s[i+poz]!=truf[i])
ok=0;
if(ok==1)
{
poz+=5;
return 1;
}
ok=1;
for(i=0; i<=4; i++)
if(s[i+poz]!=falsf[i])
ok=0;
if(ok==1)
{
poz+=6;
return 0;
}
if(s[poz]>='A' && s[poz]<='Z')
{
poz+=2;
return val[s[poz-2]-'A'];
}
return 5;
}
bool termen()
{
bool ans;
if(fnot()==1)
return !termen();
if(s[poz]=='(')
{
poz++;
ans=expresie();
poz++;
}
else
ans=crtval();
return ans;
}
bool fand()
{
bool ans=termen();
int t;
while(crtop()==2)
{
poz+=4;
ans=si(ans,termen());
}
return ans;
}
bool expresie()
{
bool ans=fand();
int t;
while(crtop()==3)
{
poz+=3;
ans=sau(ans,fand());
}
return ans;
}
int main()
{
int n,i,a=0;
char c;
in.get(s,1050);
in>>n;
for(i=1; i<=n; i++)
{
in>>c;
val[c-'A']=1-val[c-'A'];
poz=0;
out<<expresie();
}
return 0;
}