Pagini recente » Cod sursa (job #1062786) | Cod sursa (job #2352784) | Cod sursa (job #2527367) | Cod sursa (job #2548149) | Cod sursa (job #2063672)
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#define is() if(a[i]==' ')++i
#define cuv() while(a[i]>='A')++i
using namespace std;
ifstream f("bool.in");
ofstream g("bool.out");
int i,n;char o,a[1002];
bool val['Z'+1];
bool evala();
bool getval();
bool eval()
{
bool t=evala();
if(a[i]==')'){++i;is();return t;}
while (a[i]=='O'){cuv();is();t=t||evala();}//OR
return t;
}
bool evala()
{
bool t=getval();
while(a[i]=='A'){cuv();is();t=t&&getval();}//AND
return t;
}
bool getval()
{
bool t=0;
if(a[i]=='('){++i;is();
return eval()^t;}
while(a[i+1]=='O'){cuv();is();t=!t;}//NOT
if (a[i+1]=='R'){cuv();is();return !t;}//TRUE
if (a[i+1]=='A'){cuv();is();return t;}//FALSE
t=t^val[a[i]];cuv();is();
return t;
}
int main()
{
f.getline(a,1001);
f>>n;
for(int q=1;q<=n;++q)
{
f>>o;i=0;
val[o]=!val[o];
g<<eval();
}
}