Cod sursa(job #2907158)

Utilizator CReaper1116Shang Cheng Lin CReaper1116 Data 29 mai 2022 00:09:42
Problema Bool Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.86 kb
#include <fstream>

using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
char v[100000];
int cnt = 0,cnt2 = 0;
bool cod[26];
bool pexp();
bool sce(){
    int r = 0;
    if(v[cnt2] == '('){
        cnt2 = cnt2 + 1;
        r = pexp();
        cnt2++;
    }else if(v[cnt2] == 'N' && v[cnt2 + 1] == 'O' && v[cnt2 + 2] == 'T'){
        //fout<<"enotgate\n";
        if(v[cnt2 + 3] == '('){
            cnt2 = cnt2 + 3;
            r = pexp()^1;
            cnt2++;
        }else{
            cnt2 = cnt2 + 3;
            r = cod[v[cnt2] - 'A']^1;
            cnt2++;
        }
    }else if(v[cnt2] == 'T' && v[cnt2 + 1] == 'R' && v[cnt2 + 2] == 'U' && v[cnt2 + 3] == 'E'){
        r = 1;
        cnt2+=4;
    }else if(v[cnt2] == 'F' && v[cnt2 + 1] == 'A' && v[cnt2 + 2] == 'L' && v[cnt2 + 3] == 'S' && v[cnt2 + 4] == 'E'){
        r = 0;
        cnt2+=5;
    }else{
        r = cod[v[cnt2] - 'A'];
        //fout<<"char:"<<v[cnt2]<<' '<<r<<'\n';
        cnt2 = cnt2 + 1;
    }
    //fout<<"got sce:"<<r<<'\n';
    return r;
}
bool pexp(){
    int r = 0,m,b;
    r = sce();
    while(v[cnt2] != ')' && v[cnt2] != '?'&& cnt2 < cnt){
        ///get and or or
        if(v[cnt2] == 'A' && v[cnt2 + 1] == 'N' && v[cnt2 + 2] == 'D')m = 1,cnt2+=3;
        else if(v[cnt2] == 'O' && v[cnt2 + 1] == 'R')m = 0,cnt2+=2;
        b = sce();
        if(m == 1)r = r&b;
        else r = r|b;
        ///get pexp or single char
    }
    //fout<<"got pexp:"<<r<<'\n';
    return r;
}
int main()
{
    int n,i;
    char ch,a;
    ch = fin.get();
    while(ch != '\n'){
        if(ch != ' ')v[cnt++] = ch;
        ch = fin.get();
    }
    v[cnt] = '?';
    //for(i=  0;i <= cnt;i++)fout<<v[i];
    fin>>n;
    for(i = 0;i < n;i++){
        fin>>a;
        cod[a - 'A']^=1;
        cnt2 = 0;
        fout<<pexp();
    }
    return 0;
}