Pagini recente » Cod sursa (job #408180) | Cod sursa (job #588970) | Cod sursa (job #258191) | Cod sursa (job #1455579) | Cod sursa (job #2209782)
#include <fstream>
#include <cstring>
using namespace std;
char s[1005];
int i;
bool V[200];
bool getexp();
bool getterm();
bool getfact();
bool getfact()
{
bool nr=0;
if(s[i]=='(')
{
i++;
nr=getexp();
i++;
return nr;
}
if(s[i]=='T' and s[i+1]=='R')
{
i+=5;
return 1;
}
if(s[i]=='F' and s[i+1]=='A')
{
i+=6;
return 0;
}
if(s[i]=='N' and s[i+1]=='O')
{
i+=4;
return (1-getfact());
}
bool val=V[s[i]];
i+=2;
return val;
}
bool getterm()
{
bool nr=getfact();
while(s[i]=='A' and s[i+1]=='N')
{
i+=4;
nr=nr&getfact();
}
return nr;
}
bool getexp()
{
bool nr=getterm();
while(s[i]=='O' and s[i+1]=='R')
{
i+=3;
nr=nr|getterm();
}
return nr;
}
int main()
{
ifstream f("bool.in");
ofstream g("bool.out");
f.get(s,1005);
int n;
f>>n;
for(int t=1;t<=n;t++)
{
char c;
f>>c;
V[c]=1-V[c];
i=0;
g<<getexp();
}
return 0;
}