Pagini recente » Cod sursa (job #2808270) | Cod sursa (job #2507857) | Cod sursa (job #3180194) | Cod sursa (job #250818) | Cod sursa (job #3278819)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
const int NMAX = 1000;
int b[NMAX+1];
char s[NMAX+1], *p;
char mod[NMAX+1]; int n;
int eval(); int nr();
int nr()
{
int x = 0;
if(*p == '(')
{
p++;
x = eval();
p++;
}
else
{
if(*p == 'N' && *(p + 1) == 'O' && *(p + 2) == 'T')
{
p += 3;
while (*p == ' ') p++;
x = !nr();
}
else if(*p >= 'A' && *p <= 'Z')
{
x = b[*p - 'A'];
p++;
while (*p == ' ') p++;
}
else if(*p == 'T' && *(p + 1) == 'R' && *(p + 2) == 'U' && *(p + 3) == 'E')
{
p += 4;
x = 1;
}
else if(*p == 'F' && *(p + 1) == 'A' && *(p + 2) == 'L' && *(p + 3) == 'S' && *(p + 4) == 'E')
{
p += 5;
x = 0;
}
}
return x;
}
int eval()
{
int x = nr();
while((*p == 'A' && *(p + 1) == 'N' && *(p + 2) == 'D') || (*p == 'O' && *(p + 1) == 'R'))
{
if(*p == 'A' && *(p + 1) == 'N' && *(p + 2) == 'D')
{
p += 3;
while (*p == ' ') p++;
x = x & nr();
}
else if(*p == 'O' && *(p + 1) == 'R')
{
p += 2;
while (*p == ' ') p++;
x = x | nr();
}
}
return x;
}
int main()
{
fin.getline(s, NMAX);
p = s;
fin >> n;
fin >> mod;
for(int i = 0; i < n; i++)
{
b[mod[i] - 'A'] = 1 - b[mod[i] - 'A'];
p = s;
fout << eval();
}
return 0;
}