Cod sursa(job #2907166)

Utilizator CReaper1116Shang Cheng Lin CReaper1116 Data 29 mai 2022 01:06:01
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.92 kb
#include <fstream>
#include <iostream>
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++;
        r = pexp();
        cnt2++;
    }else if(v[cnt2] == 'N' && v[cnt2 + 1] == 'O' && v[cnt2 + 2] == 'T'){
        //fout<<"enotgate\n";
        cnt2 = cnt2 + 3;
        r = 1^sce();
    }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;
    }
    //cout<<"got sce:"<<r<<' '<<cnt2<<'\n';
    return r;
}
bool andexp(){
    int r;
    r = sce();
    while(cnt2 < cnt && v[cnt2] == 'A' && v[cnt2 + 1] == 'N' && v[cnt2 + 2] == 'D'){
        cnt2 = cnt2 + 3;
        r = (r&sce());
    }
    //cout<<"got andexp:"<<r<<' '<<cnt2<<'\n';
    return r;
}
bool pexp(){
    int r = 0,m,b;
    r = andexp();
    while(cnt2 < cnt && v[cnt2] != ')'){
        //cout<<"proceessing pexp "<<cnt2<<'\n';
        ///get OR CMDS
        if(v[cnt2] == 'O' && v[cnt2 + 1] == 'R'){
            cnt2 = cnt2 + 2;
            r = r|andexp();
        }else cout<<cnt2<<"error";
        ///get pexp or single char
    }
    //cout<<"got pexp:"<<r<<' '<<cnt2<<'\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;
}