Pagini recente » Istoria paginii runda/concurs_runda1 | Monitorul de evaluare | Cod sursa (job #1020648) | Cod sursa (job #1840080) | Cod sursa (job #2140324)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
int F[200], L, M, pos;
char s[1005], Sol[105];
int expresie();
int termen();
int factor();
int expresie(){
int R = termen();
while( pos < L && s[pos] == ' ' || (s[pos] == 'O' && s[pos + 1] == 'R') ){
if( s[pos] == ' ' )
pos++;
if(s[pos] == 'O' && s[pos + 1] == 'R'){
pos += 2;
R |= termen();
}
}
return R;
}
int termen(){
int R = factor();
while( pos < L && s[pos] == ' ' || (s[pos] == 'A' && s[pos + 1] == 'N') ){
if( s[pos] == ' ' )
pos++;
if(s[pos] == 'A' && s[pos + 1] == 'N'){
pos += 3;
R &= factor();
}
}
return R;
}
int factor(){
int R = 0, ok = 0;
while( pos < L && s[pos] == ' ' )
pos++;
if( s[pos] == 'N' && s[pos + 1] == 'O' ){
pos += 3;
ok = 1;
}
while( pos < L && s[pos] == ' ' )
pos++;
if( s[pos] == '(' ){
pos++;
R = expresie();
pos++;
}else{
R = F[ s[pos] - 'A' ];
pos++;
}
if( ok == 1 )
R = !R;
return R;
}
int main(){
fin.getline( s, 1005 );
L = strlen( s );
fin >> M;
for( int i = 0; i < M; i++ ){
char x; fin >> x;
F[ x - 'A' ] = !F[ x - 'A' ];
pos = 0;
int val = expresie();
Sol[i] = ( val == 1 ) ? '1' : '0';
}
fout << Sol;
return 0;
}