Pagini recente » Cod sursa (job #2278746) | Cod sursa (job #21043) | Cod sursa (job #2418976) | Cod sursa (job #1572632) | Cod sursa (job #2257568)
#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;
ifstream f("bool.in");
ofstream g("bool.out");
int i,n,j,v[30],m;
char s[1010],c;
int expresie();
int termen();
int factor();
int expresie()
{
int rasp;
int ok=0;
if(s[i]=='(')
{
i++;
rasp=termen();
i++;
}
else if(s[i]=='N'&&s[i+1]=='O')
{
i=i+4;
if(ok==1)ok=0;
else ok=1;
rasp=expresie();
}
else if(s[i]=='F'&&s[i+1]=='A')
{
i=i+6;
rasp=0;
}
else if(s[i]=='T'&&s[i+1]=='R')
{
i=i+5;
rasp=1;
}
else if(isupper(s[i]))
{
rasp=v[s[i]-'A'+1];
i=i+2;
}
if(ok==1)
{
if(rasp==1)rasp=0;
else rasp=1;
}
return rasp;
}
int factor()
{
int t=expresie();
while(s[i]=='A'&&s[i+1]=='N'&&i<=m)
{
i=i+4;
t=(t&expresie());
}
return t;
}
int termen()
{
int t=factor();
while(s[i]=='O'&&s[i+1]=='R'&&i<=m)
{
i=i+3;
t=(t|factor());
}
return t;
}
int main()
{
f.getline(s,1010);
m=strlen(s);
f>>n;
for(int j=1; j<=n; j++)
{
f>>c;
if(v[c-'A'+1]==0)v[c-'A'+1]=1;
else v[c-'A'+1]=0;
i=0;
g<<termen();
cout<<'\n';
}
return 0;
}