Pagini recente » Cod sursa (job #2183205) | Cod sursa (job #2564848) | Cod sursa (job #2329714) | Cod sursa (job #2180872) | Cod sursa (job #2842170)
/*
Lefter Sergiu - 31/01/2022
*/
#include <fstream>
using namespace std;
ifstream cin("bool.in");
ofstream cout("bool.out");
const int L = 1e3;
const int N = 1e2;
const int NL = 26;
char a[L+1], c[N+1];
int p;
bool val[NL];
bool termen();
bool expresie();
bool factor();
bool expresie()
{
bool sau = termen();
while (a[p] == '|')
{
p++;
bool t = termen();
sau = (sau || t);
}
return sau;
}
bool termen()
{
bool shi = factor();
while (a[p] == '&')
{
p++;
bool f = factor();
shi = (shi && f);
}
return shi;
}
bool factor()
{
bool rez, semn = true;
while (a[p] == '!')
{
p++;
semn = (!semn);
}
if (a[p] == '(')
{
p++;
rez = expresie();
p++;
if (!semn)
{
rez = (!rez);
}
return rez;
}
if (a[p] == '0')
{
rez = false;
}
else if (a[p] == '1')
{
rez = true;
}
else
{
rez = val[a[p] - 'A'];
}
p++;
if (!semn)
{
rez = (!rez);
}
return rez;
}
void transformare()
{
int nr = 0, i = 0;
while (a[i] != '\0')
{
if (a[i] == '0' && a[i + 1] == 'R')
{
a[nr++] = '|';
i += 2;
}
else if (a[i] == 'N' && a[i + 1] == 'O' && a[i + 2] == 'T')
{
a[nr++] = '!';
i += 3;
}
else if (a[i] == 'A' && a[i + 1] == 'N' && a[i + 2] == 'D')
{
a[nr++] = '&';
i += 3;
}
else if (a[i] == 'T' && a[i + 1] == 'R' && a[i + 2] == 'U' && a[i + 3] == 'E')
{
a[nr++] = '1';
i += 4;
}
else if (a[i] == 'F' && a[i + 1] == 'A' && a[i + 2] == 'L' && a[i + 3] == 'a' && a[i + 4] == 'E')
{
a[nr++] = '0';
i += 5;
}
else if (a[i] != ' ')
{
a[i++] = a[nr++];
}
else //daca e spatiu
{
i++;
}
}
a[nr] = '\0';
}
int main()
{
int n;
cin.getline(a, L + 1);
cin >> n >> c;
transformare();
for (int i = 0; i < n; ++i)
{
val[c[i] - 'A'] = (!val[c[i] - 'A']);
p = 0;
cout << expresie();
}
cin.close();
cout.close();
return 0;
}