Cod sursa(job #2453630)

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

using namespace std;
const int NMAX = 1010;

ifstream fin("bool.in");
ofstream fout("bool.out");

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'){
        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'){
        posMax += 4;
        ans = !NR();
    } else if(s[posMax] == 'T' && s[posMax + 1] == 'R'){
        posMax += 5;
        ans = 1;
    } else if(s[posMax] == 'F' && s[posMax + 1] == 'A'){
        posMax += 6;
        ans = 0;
    } else {
        ans = valch[v[posMax] - 'A'];
        posMax += 2;
    }
    return ans;
}

int main(){

    fin.get(s, NMAX);
    fin >> N;
    fin.get();
    fin.get(v, 105);

    for(int i = 0; i < N; i++){
        valch[v[i] - 'A'] = 1 - valch[v[i] - 'A'];
        posMax = 0;
        fout << OR();
    }
    fin.close();
    fout.close();

    return 0;
}