Pagini recente » Cod sursa (job #1750134) | Cod sursa (job #1646370) | Cod sursa (job #641906) | Cod sursa (job #2365991) | Cod sursa (job #2548325)
#include <bits/stdc++.h>
#define newline '\n'
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
///************************
string e;
unordered_map<char, bool> val{{'1', true}};
void formatEx(string& e)
{
string t;
for (int i = 0; i < (int)e.length(); i++)
{
if (e[i] == ' ')
continue;
else if (e[i] == 'T' && e[i + 1] == 'R')
{
t += '1';
i += 3;
}
else if (e[i] == 'F' && e[i + 1] == 'A')
{
t += '0';
i += 4;
}
else if (e[i] == 'A' && e[i + 1] == 'N')
{
t += '&';
i += 2;
}
else if (e[i] == 'O' && e[i + 1] == 'R')
{
t += '|';
i++;
}
else if (e[i] == 'N' && e[i + 1] == 'O')
{
t += '!';
i += 2;
}
else
t += e[i];
}
e = t;
}
///********************************************************
bool eval(), evalAND(), evalOR();
int i;
bool eval()
{
bool r = false;
while (e[i] == '!')
{
r = !r;
i++;
}
if (e[i] == '(')
{
i++;
r ^= evalOR();
i++;
}
else
{
if (r == val[e[i]])
r = 0;
else
r = 1;
i++;
}
return r;
}
bool evalAND()
{
bool r = eval();
while (e[i] == '&')
{
i++;
bool x = eval();
r = (r && x);
}
return r;
}
bool evalOR()
{
bool r = evalAND();
while (e[i] == '|')
{
i++;
bool x = evalAND();
r = (r || x);
}
return r;
}
int main()
{
getline(fin, e);
formatEx(e);////A&((B|!C)|((1)))
int q;
fin >> q;
while (q--)
{
char c;
fin >> c;
val[c] = !val[c];
i = 0;
fout << evalOR();
}//*/
return 0;
}