Pagini recente » Cod sursa (job #1272235) | Cod sursa (job #1440880) | Cod sursa (job #2057266) | Cod sursa (job #60643) | Cod sursa (job #3237754)
#include <fstream>
#include <cstring>
using namespace std;
ifstream cin("bool.in");
ofstream cout("bool.out");
char newS[1002],com[1002],s[1002],dummy[1];
bool frecv[27];
const int chardif=65;
int i,n;
bool AND(),NOT(),elem();
bool OR()
{
bool or_op = AND();
while(newS[i]=='o')
{
i++;
or_op=or_op || AND();
}
return or_op;
}
bool AND()
{
bool and_op = NOT();
while(newS[i]=='a')
{
i++;
and_op=and_op && NOT();
}
return and_op;
}
bool NOT()
{
bool not_op = 0;
while(newS[i]=='n')
{
not_op=!not_op;
i++;
}
return not_op^elem();
}
bool elem()
{
if(newS[i]=='(')
{
i++;
bool val=OR();
i++;
return val;
}
i++;
if(newS[i-1]=='1'||newS[i-1]=='0')
return newS[i-1]-'0';
return frecv[newS[i-1]-chardif];
}
int main()
{
cin.getline(s,1002);
cin>>n;
cin.getline(dummy,1);
cin.getline(com,1002);
int lastptr=0,poz,lenght = strlen(s),newSl=-1;
for(i=0; i<lenght; i++)
{
if((s[i]==' '||s[i]=='('||s[i]==')')&&s[lastptr]!=' ')
{
char subs[1002]="";
for(int j=lastptr;j<i;j++)
subs[j-lastptr]=s[j];
if(strcmp(subs,"TRUE")==0)
newS[++newSl]='1';
else if(strcmp(subs,"FALSE")==0)
newS[++newSl]='0';
else if(strcmp(subs,"NOT")==0)
newS[++newSl]='n';
else if(strcmp(subs,"AND")==0)
newS[++newSl]='a';
else if(strcmp(subs,"OR")==0)
newS[++newSl]='o';
else
newS[++newSl]=subs[0];
if(s[i]==' ')
lastptr=i+1,i++;
else
lastptr=i;
}
while(s[i]=='('||s[i]==')')
newS[++newSl]=s[i],i++,lastptr++;
if(s[i]==' ')
lastptr++;
}
//cout<<newS<<'\n';
int l2=strlen(com);
for(int j=0; j<l2; j++)
{i=0;
frecv[com[j]-chardif]= !frecv[com[j]-chardif];
cout<<OR();
}
return 0;
}