Cod sursa(job #2230165)

Utilizator LorenaMariaHantig Lorena LorenaMaria Data 9 august 2018 12:41:48
Problema Bool Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream in("bool.in");
ofstream out("bool.out");
char e[1005],c,*p;
int n,v[26];
int OR(char *s);
int AND(char *s);
int verif(char *s);
int OR(char e[])
{ int t=AND(e);
  while(*p=='O' && *(p+1)=='R')
  { p+=2;
    t=t|AND(e);
  }
  return t;
}
int AND(char e[])
{ int t=verif(e);
  while(*p=='A' && *(p+1)=='N')
  { p+=3;
    t=t&verif(e);
  }
  return t;
}
int verif(char e[])
{ bool t,ok=0;
  if(*p=='N' && *(p+1)=='O')
  { p+=3;
    ok=1;
    t=verif(e);
  }
  else if(*p=='(')
  { p++;
    t=OR(e);
    p++;
  }
  else if(*p=='T' && *(p+1) == 'R')
    p+=4,t=1;
  else if(*p=='F' && *(p+1)=='A')
    p+=5,t=0;
  else
    t=v[*p-'A'],p++;
  if(ok)
     return 1-t;
  return t;
}
void eliminare(char *s)
{ while(*s)
    if(*s==' ')
       strcpy(s,s+1);
    else
       s++;
}
int main()
{ in.getline(e,1005);
  in>>n;
  in.get();
  eliminare(e);
  while(n--)
  { in.get(c);
    v[c-'A']=1-v[c-'A'];
    p=e;
    out<<OR(e);
  }
  in.close();
  out.close();
  return 0;
}