Pagini recente » Gruparea testelor | Cod sursa (job #2351164) | Cod sursa (job #1110239) | Cod sursa (job #486703) | Cod sursa (job #1050409)
#include <cstdio>
#define MAX 1005
int N, sgm[35];
char S[MAX], *p;
int OR(void);
int AND(void);
int fact(void);
void solve(void);
int main()
{
freopen("bool.in","r",stdin);
freopen("bool.out","w",stdout);
solve();
return 0;
}
int OR()
{
int rez=AND();
if ( *p == 'O' && *(p + 1) == 'R') // - > OR
p += 3, rez |= AND();
return rez;
}
int AND()
{
int rez = fact();
while ( *p == 'A' && *(p + 1) == 'N') // - > AND
p += 4, rez &= fact();
return rez;
}
int fact()
{
int rez;
if ( *p == 'N' && *(p + 1) == 'O') // - > NOT
p += 4, rez = !fact();
else if ( *p == 'T' && *(p + 1) == 'R') // - > TRUE
p += 5, rez = 1;
else if ( *p == 'F' && *(p + 1) == 'A') // - > FALSE
p += 6, rez = 0;
else if ( *p == '(') // trecem peste (, apoi peste )
++p, rez = OR(), ++p;
else
rez = sgm[ *p - 'A'], p += 2;
return rez;
}
void solve()
{
int i;
char c;
fgets(S, MAX, stdin);
scanf("%d\n",&N);
for (i=0; i<N; ++i)
{
scanf("%c",&c);
sgm[c - 'A'] = ! sgm[c - 'A'];
p = S;
printf("%d",OR());
}
}