Cod sursa(job #1203698)

Utilizator apopeid15Apopei Daniel apopeid15 Data 1 iulie 2014 09:18:40
Problema Bool Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <cstdio>
#include <cstring>
 
using namespace std;
 
const int knmax = 2e3;
 
bool vals[300];
char *p, given_expr[knmax];
 
bool oring();
bool anding();
bool absolute();
 
bool oring(){
  bool t = anding();
  while(*p == ' ' && *(p + 1) == 'O' && *(p + 2) == 'R'){
    p += 4;
    t |= anding();
  }
  return t;
}
 
bool anding(){
  bool t = absolute();
  while(*p == ' ' && *(p + 1) == 'A' && *(p + 2) == 'N'){
    p += 5;
    t &= absolute();
  }
  return t;
}
 
bool absolute(){
  bool t;
  if(*p == 'N' && *(p + 1) == 'O'){
    p += 4;
    t = !(absolute());
  }
  else if(*p == 'F' && *(p + 1) == 'A'){
    p += 5;
    t = false;
  }
  else if(*p == 'T' && *(p + 1) == 'R'){
    p += 4;
    t = true;
  }
  else if(*p == '('){
    ++p;
    t = oring();
    ++p;
  }
  else{
    t = vals[(*p)];
    p += 1;
  }
  return t;
}
 
char ans[knmax];
 
int main(){
  freopen("bool.in", "r", stdin);
  freopen("bool.out", "w", stdout);
 
  gets(given_expr);
  int n;
  scanf("%d\n", &n);
  for(int i = 0; i < n; ++i){
    char x;
    scanf("%c", &x);
    vals[x] = !vals[x];
    p = given_expr;
    if(oring())
      ans[i] = 1 + '0';
    else
      ans[i] = 0 + '0';
  }
 
  puts(ans);
 
  return 0;
}