Pagini recente » Cod sursa (job #2642807) | Cod sursa (job #1157852) | Cod sursa (job #3178288) | Cod sursa (job #2455962) | Cod sursa (job #1363396)
#include <fstream>
#include <cstring>
#define DIM 1010
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
int n, lenght, k, index;
char x[DIM], S[DIM], ch, v[DIM];
bool function_AND();
bool function_NOT();
bool function_OR();
bool function_OR(){
bool result = function_AND();
while(v[index] == 'O' && v[index + 1] == 'R')
{
index += 2;
result |= function_AND();
}
return result;
}
bool function_AND(){
bool result = function_NOT();
while(v[index] == 'A' && v[index + 1] == 'N' && v[index + 2] == 'D')
{
index += 3;
result &= function_NOT();
}
return result;
}
bool function_NOT(){
bool result = 0;
if(v[index] == 'N' && v[index + 1] == 'O' && v[index + 2] == 'T')
{
index += 2;
result = !function_NOT();
}
else
{
if(v[index] == '(')
{
index ++;
result = function_OR();
index ++;
}
else
{
if(v[index] == '0' || v[index] == '1')
{
result = v[index] - '0';
index ++;
}
}
}
return result;
}
int main()
{
fin.get(S, 1001);
fin >> n;
for(int i = 1; i <= n; i++)
{
fin >> ch;
if(x[ch] == 1)
{
x[ch] = 0;
}
else
{
x[ch] = 1;
}
k = 0;
lenght = strlen(S);
for(int j = 0; j < lenght; j ++)
{
if(S[j] == 'T' && S[j + 1] == 'R' && S[j + 2] == 'U' && S[j + 3] == 'E')
{
v[k ++] = '1';
j += 3;
continue;
}
if(S[j] == 'F' && S[j + 1] == 'A' && S[j + 2] == 'L' && S[j + 3] == 'S' && S[j + 4] == 'E')
{
v[k ++] = '0';
j += 4;
continue;
}
if(S[j] != ' ')
{
if (S[j] >= 'A' && S[j]<='Z' && ( !(S[j + 1] >= 'A' && S[j + 1] <= 'Z') && !(S[j - 1]>='A' && S[j - 1]<='Z')))
{
v[k ++] = '0' + x[ S[j] ];
}
else
{
v[k ++] = S[j];
}
}
}
index = 0;
fout << function_OR();
}
return 0;
}