Pagini recente » Cod sursa (job #2403035) | Cod sursa (job #1686125) | Cod sursa (job #1508371) | Cod sursa (job #228584) | Cod sursa (job #1428213)
#include <cstdio>
#include <algorithm>
#include <cstring>
#define Nmax 1004
#define Mmax 104
using namespace std;
int n, i, j, m, p;
char s[Nmax], vm[Nmax];
bool v[28];
int fact();
int evalNOT();
int evalAND();
int evalOR();
int evalOR()
{
int x = evalAND();
if (s[p] == ' ') ++p;
while (s[p] == 'O' && s[p + 1] == 'R')
{
p += 2;
if (s[p] == ' ') ++p;
x ^= evalAND();
}
return x;
}
int evalAND()
{
int x = evalNOT();
if (s[p] == ' ') ++p;
while (s[p] == 'A' && s[p + 1] == 'N')
{
p += 3;
if (s[p] == ' ') ++p;
x &= evalNOT();
}
return x;
}
int evalNOT()
{
int x = fact();
if (s[p] == ' ') ++p;
while (s[p] == 'N' && s[p + 1] == 'O' )
{
p += 3;
if (s[p] == ' ') ++p;
x != fact();
}
return x;
}
int fact()
{
int x = 0;
if (s[p] == ' ') ++p;
if (s[p] == '(')
{
++p;
if (s[p] == ' ') ++p;
x = evalOR();
++p;
if (s[p] == ' ') ++p;
}
else
{
if (s[p] == ' ') ++p;
if (s[p] == 'T' && s[p + 1] == 'R' && s[p + 2] == 'U' && s[p + 3] == 'E')
{
x = 1;
p += 3;
}
if (s[p] == 'F' && s[p + 1] == 'A' && s[p + 2] == 'L' && s[p + 3] == 'S' && s[p + 4] == 'E')
{
x = 0;
p += 4;
}
x = v[s[p] - 'A'];
if (s[p] == ' ') ++p;
}
return x;
}
int main()
{
freopen("bool.in", "r", stdin);
freopen("bool.out", "w", stdout);
gets(s + 1);
n = strlen(s + 1);
scanf("%d\n", &m);
gets(vm + 1);
for (i = 1; i <= m; ++i)
{
if (v[vm[i]-'A']) v[vm[i]-'A'] = 0;
else v[vm[i]-'A'] = 1;
p = 1;
printf("%d", evalOR());
}
return 0;
}