Cod sursa(job #3214920)

Utilizator TheEpicWipedCreaVlad Chirita Alexandru TheEpicWipedCrea Data 14 martie 2024 16:03:22
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in  ("bool.in");
ofstream out("bool.out");

#define maxN 1000

bool vc['z'-'a'+1];
char s[maxN+1];
char aux[maxN+1];

bool expresie();
bool termen();
bool ceva();
int i;

bool expresie(){
    bool ans=termen();
    while(s[i]=='O' && s[i+1]=='R'){
        i+=2;
        ans|=termen();
    }
    return ans;
}

bool termen(){
    bool ans=ceva();
    while(s[i]=='A' && s[i+1]=='N' && s[i+2]=='D'){
        i+=3;
        ans&=ceva();
    }
    return ans;
}

bool ceva(){
    bool ans;
    if(s[i]=='('){
        i++;
        ans=expresie();
        i++;
    }
    else if(s[i]=='F' && s[i+1]=='A' && s[i+2]=='L'){
        ans=0;
        i+=5;
    }
    else if(s[i]=='T' && s[i+1]=='R'){
        ans=1;
        i+=4;
    }
    else if(s[i]=='N' && s[i+1]=='O' && s[i+2]=='T'){
        i+=3;
        ans=!ceva();
    }
    else if(isalpha(s[i])){
        ans=vc[s[i]-'A'];
        i++;
    }
    return ans;
}

int main(){
    in.getline(aux,sizeof(aux));
    for(int j=0;aux[j];j++){
        if(aux[j]!=' '){
            s[i]=aux[j];
            i++;
        }
    }
    int n;
    in>>n;
    while(n){
        char x;
        in>>x;
        vc[x-'A']^=1;
        i=0;
        out<<expresie();
        n--;
    }
}