Pagini recente » Borderou de evaluare (job #1110185) | Cod sursa (job #1110176)
#include <iostream>
#include <fstream>
using namespace std;
const int Lmax = 1000;
const int Sigma = 26;
char expr[Lmax + 1];
int val[Sigma + 1];
int N, point;
int eval_or();
int eval_and();
int termen();
int termen()
{
if ( expr[ point ] == 'N' && expr[ point + 1 ] == 'O' && expr[ point + 2 ] == 'T' )
{
point += 4;
int s = ( !termen() );
return s;
}
if ( expr[ point ] == '(' )
{
point++;
int s = eval_or();
point++;
return s;
}
if ( expr[ point ] == 'T' && expr[ point + 1 ] == 'U' )
{
point += 4;
return 1;
}
if ( expr[ point ] == 'F' && expr[ point + 1 ] == 'A' )
{
point += 5;
return 0;
}
if ( 'A' <= expr[ point ] && expr[ point ] <= 'Z' )
{
point++;
return val[ expr[ point - 1 ] - 'A' ];
}
}
int eval_and()
{
int t = termen();
while ( expr[ point ] == 'A' && expr[ point + 1 ] == 'N' && expr[ point + 2 ] == 'D' )
{
point += 5;
t &= termen();
}
return t;
}
int eval_or()
{
int t = termen();
while ( expr[ point ] == 'O' && expr[ point + 1 ] == 'R' )
{
point += 4;
t |= eval_and();
}
return t;
}
int main()
{
freopen("bool.in", "r", stdin);
freopen("bool.out", "w", stdout);
char c;
gets( expr + 1 );
scanf("%d\n", &N);
for ( int i = 0; i < N; ++i )
{
scanf("%c", &c);
val[ c - 'A' ] ^= 1;
point = 1;
cout << eval_or();
}
return 0;
}