Pagini recente » Cod sursa (job #528256) | Cod sursa (job #2498180) | Cod sursa (job #3180307) | Cod sursa (job #3144103) | Cod sursa (job #3144604)
#include <fstream>
#include <string>
using namespace std;
ifstream cin("bool.in");
ofstream cout("bool.out");
string a, s;
int i;
int n;
bool f[26];
// XOR < AND < OR
bool OR();
bool AND();
bool XOR();
int main()
{
getline(cin, a);
i = 0;
while(a[i])
{
if (a[i] == ' ')
i++;
if (a[i] == 'A' && a[i + 1] == 'N')
s += "&", i += 3;
else if (a[i] == 'O' && a[i + 1] == 'R')
s += "|", i += 2;
else if (a[i] == 'N' && a[i + 1] == 'O')
s += "1^", i += 3;
else if (a[i] == 'T' && a[i + 1] == 'R')
s += "1", i += 4;
else if (a[i] == 'F' && a[i + 1] == 'A')
s += "0", i += 5;
else
s += a[i], i++;
}
cin >> n;
while(n--)
{
char x;
cin >> x;
f[x - 'A'] = !f[x - 'A'];
i = 0;
cout << OR();
}
return 0;
}
// XOR < AND < OR
bool OR()
{
bool rez = AND();
while(s[i] == '|')
{
i++;
rez |= AND();
}
return rez;
}
bool AND()
{
bool rez = XOR();
while(s[i] == '&')
{
i++;
rez &= XOR();
}
return rez;
}
bool XOR()
{
bool rez;
if(s[i] == '(')
{
i++;
rez = OR();
i++;
}
else if(s[i] >= 'A' && s[i] <= 'Z')
{
rez = f[s[i] - 'A'];
i++;
}
else
{
rez = s[i] - '0';
i++;
}
return rez;
}