Pagini recente » Cod sursa (job #1119184) | Cod sursa (job #1811251) | Cod sursa (job #2079296) | Cod sursa (job #2757570) | Cod sursa (job #2950625)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
//expresie = factor si factor si factor....
//factor = termen sau termen sau termen...
//termen = fie expresie, fie nu de expresie
bool f['z' - 'a' + 3];
char s[1003];
bool expresie();
bool factor();
bool termen();
int i;
string cuv;
string cuvant()
{
string ans;
do
{
ans += s[i++];
}
while (s[i] and s[i] != ' ' and s[i] != '(');
return ans;
}
bool expresie()
{
bool ans = 1;
do
{
ans &= factor();
}
while (cuv == "AND");
return ans;
}
bool factor()
{
bool ans = 0;
do
{
ans |= termen();
cuv = cuvant();
i++;
}
while (cuv == "OR");
return ans;
}
bool termen()
{
bool ans;
string ce = cuvant();
if (ce.size() == 1)
{
if (isalpha(ce[0]))
{
ans = f[ce[0] - 'A'];
}
else
{
i++;
ans = expresie();
}
}
else
{
if (ce == "TRUE")
{
ans = 1;
}
if (ce == "FALSE")
{
ans = 0;
}
if (ce == "NOT")
{
i++;
ans = !expresie();
}
}
i++;
return ans;
}
int main()
{
ifstream cin("bool.in");
ofstream cout("bool.out");
//A AND ((B OR NOT C) OR ((TRUE)))
cin.getline(s, sizeof(s));
int n;
cin >> n;
while (n--)
{
char x;
cin >> x;
f[x - 'A'] ^= 1;
i = 0;
cout << expresie();
}
}