Pagini recente » Cod sursa (job #1826525) | Cod sursa (job #1898832) | Cod sursa (job #2026246) | Cod sursa (job #838058) | Cod sursa (job #2947263)
#include <fstream>
#include <string>
#include <string.h>
using namespace std;
ifstream cin ("bool.in");
ofstream cout ("bool.out");
const int N = 1002;
string s;
char a[N + 1], ch;
int f[30];
int n, i;
bool term ();
bool fact();
bool rest();
bool evaluate ()
{
bool val = term();
while (s[i] == 'O')
{
i += 2;
val |= (term());
}
return val;
}
bool term ()
{
bool val = fact();
while (s[i] == 'A' && s[i + 1] == 'N')
{
i += 3;
val &= fact();
}
return val;
}
bool fact ()
{
bool val = rest();
while (s[i] == 'N')
{
i += 3;
val = !rest();
}
return val;
}
bool rest ()
{
bool val = 0;
if (s[i] == '(')
{
++i;
val = evaluate();
++i;
}
else
{
if (s[i] == 'T' && s[i + 1] == 'R')
val = 1, i += 4;
else if (s[i] == 'F' && s[i + 1] == 'A')
val = 0, i += 5;
else
{
val = f[s[i] - 'A'];
++i;
}
}
return val;
}
int main()
{
cin.getline(a, 1001);
for (int i = 0; i < strlen(a); ++i)
if (!isspace(a[i]))
s += a[i];
cin >> n;
for (int j = 1; j <= n; ++j)
{
cin >> ch;
f[ch - 'A'] ^= 1;
i = 0;
cout << evaluate();
}
return 0;
}