Cod sursa(job #2453624)

Utilizator Senth30Denis-Florin Cringanu Senth30 Data 4 septembrie 2019 19:49:35
Problema Bool Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.48 kb
#include <bits/stdc++.h>

using namespace std;
const int NMAX = 1010;

int N, posMax;
int valch[30];
char s[NMAX], v[105];

bool OR();
bool AND();
bool NR();

bool OR(){
    bool ans = AND();
    while(s[posMax] == 'O' && s[posMax + 1] == 'R'){
        posMax += 3;
        ans = ans|AND();
    }
    return ans;
}

bool AND(){
    bool ans = NR();
    while(s[posMax] == 'A' && s[posMax + 1] == 'N' && s[posMax + 2] == 'D'){
        posMax += 4;
        ans = ans&NR();
    }
    return ans;
}

bool NR(){
    bool ans = 0;
    if(s[posMax] == '('){
        posMax++;
        ans = OR();
        posMax++;
    } else if(s[posMax] == 'N' && s[posMax + 1] == 'O' && s[posMax + 2] == 'T'){
        posMax += 4;
        ans = !NR();
    } else if(s[posMax] == 'T' && s[posMax + 1] == 'R' && s[posMax + 2] == 'U' && s[posMax + 3] == 'E'){
        posMax += 5;
        ans = 1;
    } else if(s[posMax] == 'F' && s[posMax + 1] == 'A' && s[posMax + 2] == 'L' && s[posMax + 3] == 'S' && s[posMax + 4] == 'E'){
        posMax += 6;
        ans = 0;
    } else {
        ans = valch[v[posMax] - 'A'];
        posMax += 2;
    }
    return ans;
}

int main(){

    freopen("bool.in", "r", stdin);
    freopen("bool.out", "w", stdout);

    cin.get(s, NMAX);
    scanf("%d ", &N);
    cin.get(v, 105);

    for(int i = 0; i < N; i++){
        valch[v[i] - 'A'] = 1 - valch[v[i] - 'A'];
        posMax = 0;
        printf("%d", OR());
    }

    return 0;
}