# Cod sursa(job #2436880)

Utilizator Data 7 iulie 2019 14:58:46 Bool 20 cpp-64 done Arhiva de probleme 1.77 kb
``````#include <bits/stdc++.h>

using namespace std;

ifstream fin("bool.in");
ofstream fout("bool.out");

char expresie[1010], v[110], val[30];
int n, p;

bool IsOr();
bool IsAnd();
bool GetVar();
void Spatiu();

void Spatiu()
{
while (expresie[p] == ' ') ++p;
}

bool IsOr()
{
bool r = IsAnd();
while (expresie[p] == 'O' && expresie[p + 1] == 'R')
{
p = p + 2;
Spatiu();
r = r || IsAnd();
}
return r;
}

bool IsAnd()
{
bool r = GetVar();
while (expresie[p] == 'A' && expresie[p + 1] == 'N' && expresie[p + 2] == 'D')
{
p = p + 3;
Spatiu();
r = r && GetVar();
}
return r;
}

bool GetVar()
{
bool r;
if (expresie[p] == 'N' && expresie[p + 1] == 'O' && expresie[p + 2] == 'T')
{
p = p + 3;
Spatiu();
r = !GetVar();
}
else if (expresie[p] == '(')
{
p = p + 1;
r = IsOr();
p = p + 1;
}
else if (expresie[p] == 'T' && expresie[p + 1] == 'R' && expresie[p + 2] == 'U' && expresie[p + 3] == 'E')
{
p = p + 4;
Spatiu();
r = true;
}
else if (expresie[p] == 'F' && expresie[p + 1] == 'A' && expresie[p + 2] == 'L' && expresie[p + 3] == 'S' && expresie[p + 4] == 'E')
{
p = p + 5;
Spatiu();
r = false;
}
else
{
r = val[expresie[p] - 'A'];
p = p + 1;
Spatiu();
}
return r;
}

int main()
{
fin.get(expresie, 1005);
fin >> n;
fin.get();
fin.get(v, 105);
for (int i = 0; i < strlen(v); ++i)
{
val[v[i] - 'A'] = !val[v[i] - 'A'];
p = 0;
fout << IsOr();
}
fin.close();
fout.close();
return 0;
}
``````