Pagini recente » Cod sursa (job #2698101) | Cod sursa (job #1760511) | Cod sursa (job #1619753) | Cod sursa (job #3249071) | Cod sursa (job #2946909)
#include <fstream>
using namespace std;
ifstream cin ("bool.in");
ofstream cout ("bool.out");
const int N = 1002;
char s[N + 1], ch;
int f[30];
int n, i;
bool term ();
bool fact();
bool rest();
bool evaluate ()
{
bool val = term();
while (s[i] == 'N')
{
i += 4, val = !(term());
}
return val;
}
bool term ()
{
bool val = fact();
while (s[i] == 'A' && s[i + 1] == 'N')
{
i += 4;
val &= fact();
}
return val;
}
bool fact ()
{
bool val = rest();
while (s[i] == 'O')
{
i += 3;
val |= rest();
}
return val;
}
bool rest ()
{
int 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;
if (isspace(s[i]))
++i;
}
}
return val;
}
int main()
{
cin.getline(s, 1001);
cin >> n;
for (int j = 1; j <= n; ++j)
{
cin >> ch;
f[ch - 'A'] ^= 1;
i = 0;
cout << evaluate();
}
return 0;
}