Pagini recente » Cod sursa (job #2552772) | Cod sursa (job #624443) | Cod sursa (job #2732662) | Cod sursa (job #2607385) | Cod sursa (job #2680407)
#include<bits/stdc++.h>
using namespace std;
ifstream f("bool.in");
ofstream o("bool.out");
FILE*in=fopen("bool.in","r");
FILE*out=fopen("bool.out","w");
int n,i;
char c[1006],v=0;
bool az[26];
bool is_or(int &x)
{
if(c[x]=='O'&&c[x+1]=='R'&&c[x+2]==' ')
{
x+=3;
return 0;
}
return 1;
}
bool is_and(int &x)
{
if(c[x]=='A'&&c[x+1]=='N'&&c[x+2]=='D'&&c[x+3]==' ')
{
x+=4;
return 0;
}
return 1;
}
int is_not(int &x)
{
int ct=0;
while(c[x]=='N'&&c[x+1]=='O'&&c[x+2]=='T'&&c[x+3]==' ')
{
x+=4;
ct++;
}
return ct;
}
bool get_term_or(int &x);
bool get_term_and(int &x);
bool get_exp(int &x);
bool eval(int &x)
{
bool t1=get_term_or(x),t2;
while(is_or(x)==0)
{
t2=get_term_or(x);
t1=t1|t2;
}
return t1;
}
bool get_term_or(int &x)
{
bool t1=get_term_and(x),t2;
while(is_and(x)==0)
{
t2=get_term_and(x);
t1=t1&t2;
}
return t1;
}
bool get_term_and(int &x)
{
if(is_not(x)%2==1)
{
return !get_exp(x);
}
else
{
return get_exp(x);
}
}
bool get_exp(int &x)
{
if(c[x]=='(')
{
x++;
bool bb=eval(x);
x++;
return bb;
}
if(c[x]=='T'&&c[x+1]=='R'&&c[x+2]=='U'&&c[x+3]=='E')
{
x+=5;
return 1;
}
if(c[x]=='F'&&c[x+1]=='A'&&c[x+2]=='L'&&c[x+3]=='S'&&c[x+4]=='E')
{
x+=6;
return 0;
}
else
{
bool bb=az[c[x]-65];
x+=2;
return bb;
}
}
int main()
{
i=0;
while(v!='\n')
{
v=fgetc(in);
c[i]=v;
i++;
}
fscanf(in,"%d",&n);
v=fgetc(in);
for(i=0;i<n;i++)
{
v=fgetc(in);
az[v-65]=!az[v-65];
int k=0;
fprintf(out,"%d",eval(k));
}
}