Pagini recente » Cod sursa (job #1440902) | Cod sursa (job #1673682) | Cod sursa (job #3240653) | Cod sursa (job #2518556) | Cod sursa (job #3237859)
#include <fstream>
#include <string>
using namespace std;
ifstream in("bool.in");
ofstream out("bool.out");
string e;
char s;
int i, j, n;
bool frc[300];
bool expresie();
void first_ordin(bool& x);
void second_ordin(bool& x);
bool get_number();
bool third_ordin();
bool expresie()
{
bool x = get_number();
while (i < e.size() && e[i] != ')')
{
second_ordin(x);
first_ordin(x);
}
return x;
}
bool get_number()
{
bool x = third_ordin();
i++;
if (e[i - 1] == '(')
return expresie();
bool value;
if (e[i - 1] == 'T' && e[i] == 'R')
{
i += 3;
value = 1;
}
else if (e[i - 1] == 'F' && e[i] == 'A')
{
i += 4;
value = 0;
}
else
value = frc[e[i-1]];
if (e[i] == ' ')
i++;
second_ordin(value);
if (x == 1)
return !value;
else
return value;
}
bool third_ordin()
{
if (i + 2 >= e.size() || (e[i] != 'N' || e[i + 1] != 'O')) ///avem not?
return 0;
i += 3;
if (e[i] == ' ')
i++;
return 1;
}
void second_ordin(bool& x)
{
if (i + 2 >= e.size() || (e[i] != 'A' || e[i+1] != 'N'))
return;
i += 3;
if (e[i] == ' ')
i++;
bool ok = get_number();
x = x and ok;
}
void first_ordin(bool& x)
{
if (i + 1 >= e.size() || (e[i] != 'O' || e[i + 1] != 'R'))
return;
i += 2;
if (e[i] == ' ')
i++;
bool ok = get_number();
x = x or ok;
}
int main()
{
getline(in, e);
in >> n;
for (j = 0; j < n; j++)
{
int grecu = 1;
in >> s;
frc[s] = !frc[s];
out << expresie();
i = 0;
}
}