Cod sursa(job #2562920)

Utilizator Stefan_PiscuPiscu Stefan Constantin Stefan_Piscu Data 29 februarie 2020 20:08:09
Problema Bool Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("bool.in");
ofstream fout("bool.out");

string s;
int ind;

map<char, bool> val;

bool pri0();
bool pri1();
bool pri2();
bool pri3();

bool pri0(){
  bool x=pri1();
  if(s.substr(ind, 2)=="OR"){
    ind+=2;
    while(s[ind]==' ') ind++;
    bool val=pri1();
    x=x||val;
  }
  return x;
}

bool pri1(){
  bool x=pri2();
  if(s.substr(ind, 3)=="AND"){
    ind+=3;
    while(s[ind]==' ') ind++;
    bool val=pri2();
    x=val&&x;
  }
  return x;
}

bool pri2(){
  if(s.substr(ind, 3)=="NOT"){
    ind+=3;
    while(s[ind]==' ') ind++;
    return !pri3();
  }
  return pri3();
}

bool pri3(){
  if(s.substr(ind, 4)=="TRUE"){
      ind+=4;
      while(s[ind]==' ') ind++;
      return 1;
  }
  if(s.substr(ind, 5)=="FALSE"){
    ind+=5;
    while(s[ind]==' ') ind++;
    return 0;
  }
  if(s[ind]=='('){
    ind++;
    bool sol=pri0();
    ind++;
    while(s[ind]==' ') ind++;
    return sol;
  }
  else if(s[ind]>='A'&&s[ind]<='Z'){
    bool sol=val[s[ind]];
    ind++;
    while(s[ind]==' ') ind++;
    return sol;
  }
  return 0;
}

int main()
{
  char c[1025];
  fin.getline(c, 1024);
  s=c;
  s=s+"$$$$$$$";
  for(char x='A';x<='Z';++x){
    val[x]=0;
  }
  int n;
  fin>>n;
  for(int i=1;i<=n;++i){
    char x;
    ind=0;
    fin>>x;
    val[x]=!val[x];
    fout<<pri0();
  }
  fout<<"\n";
  return 0;
}