Cod sursa(job #3212180)

Utilizator luc3lexaAlexandrescu Luca luc3lexa Data 11 martie 2024 11:43:17
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.59 kb
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
const int nmax = 1000;
bool valoare[27];
string s,s_aux;
int n,p,k;

bool litera(int &p);
bool constanta(int &p);
bool expresie(int &p);
bool sir_OR(int &p);
bool sir_AND(int &p);

bool litera(int &p){
    return valoare[s[p++] -'A'];
}
bool constanta(int &p){
    if(s[p] == 'T' && s[p+1] == 'R'){
        p += 4;
        return 1;
    }else{
        p += 5;
        return 0;
    }
};
bool expresie(int &p){
    if(s[p] == '('){
        p++;
        bool x = sir_OR(p);
        p++;
        return x;
    };
    if((s[p] == 'T' && s[p+1] == 'R') || (s[p] == 'F' && s[p+1] == 'A')){
        return constanta(p);
    };
    if(s[p] == 'N' && s[p+1] == 'O'){
        p += 3;
        return !expresie(p);
    }
    return litera(p);

}
bool sir_AND(int &p){
    bool x1 = expresie(p);
    while(p < k && s[p] == 'A'){
        p+=3;
        bool x2 = expresie(p);
        x1 &= x2;
    };
    return x1;
}
bool sir_OR(int &p){
    bool x1 = sir_AND(p);
    while(p < k && s[p] == 'O'){
        p+=2;
        bool x2 = sir_AND(p);
        x1 |= x2;
    };
    return x1;
}
int main()
{
    getline(fin,s);
    k = 0;
    for(int i = 0; i <=s.length(); i++){
        if(s[i] != ' '){
            s[k++] = s[i];
        }
    };
    s.resize(k);
    fin >> n >> s_aux;
    for(int i = 0; i < s_aux.length(); i++){
        valoare[s_aux[i]-'A'] ^= 1;
        p = 0;
        fout << sir_OR(p);
    };
    return 0;
}