Cod sursa(job #1706233)

Utilizator Mihai9Oniga Mihai Mihai9 Data 21 mai 2016 22:42:10
Problema Bool Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
int n,i;
char x[1005],ch,*p;
bool v[27],evaluare();
bool termen(){
 bool b=0;
 if(*p=='(')p++,b=evaluare(),p++;
 else if(*p=='F'&&*(p+1)=='A'){p+=6,b=0;}
 else if(*p=='T'&&*(p+1)=='R'){p+=5,b=1;}
 else if(*p=='N'&&*(p+1)=='O'){p+=4,b=!termen();}
 else {b=v[*p-'A'];p+=2;}
 return b;
}
bool factor(){
 bool b=termen();
 while(*p=='A'&&*(p+1)=='N'){p+=4,b=b&termen();}
 return b;
}
bool evaluare(){
 bool b=factor();
 while(*p=='O'&&*(p+1)=='R'){p+=3,b=b|factor();}
 return b;
}
int main(){
    fin.getline(x,1005);
    fin>>n;
    for(i=1; i<=n; i++){
     fin>>ch;
     if(v[ch-'A']=!v[ch-'A']){p=x;}
     fout<<evaluare();
    }
    return 0;
}