Cod sursa(job #2207757)

Utilizator giotoPopescu Ioan gioto Data 26 mai 2018 17:45:17
Problema Bool Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <bits/stdc++.h>
using namespace std;

int p, n;
char s[115];
bool f[30];
inline bool sau();
inline bool si();
inline bool nu();
int main()
{
    freopen("bool.in", "r", stdin);
    freopen("bool.out", "w", stdout);

    fgets(s, sizeof(s), stdin);
    scanf("%d\n", &n);

    char c;
    for(int i = 1; i <= n ; ++i){
        scanf("%c", &c);
        f[c - 'A'] = 1 - f[c - 'A'];
        p = 0;
        printf("%d", sau());
    }
    return 0;
}
inline bool sau(){
    bool x = si();
    while(s[p] == ' ') ++p;

    while(s[p] == 'O'){
        p += 2;
        while(s[p] == ' ') ++p;

        bool y = si();
        x = (x | y);

        while(s[p] == ' ') ++p;
    }
    return x;
}
inline bool si(){
    bool x = nu();
    while(s[p] == ' ') ++p;

    while(s[p] == 'A'){
        p += 3;
        while(s[p] == ' ') ++p;

        bool y = nu();
        x = (x & y);

        while(s[p] == ' ') ++p;
    }
    return x;
}
inline bool nu(){
    bool x = 0, neg = 0;

    while(s[p] == ' ') ++p;

    while(s[p] == 'N' && s[p + 1] == 'O') {
        neg = 1 - neg;
        p += 3;
        while(s[p] == ' ') ++p;
    }

    if(s[p] == '(') {++p; x = sau(); ++p;}
    else if(s[p] == 'T' && s[p + 1] == 'R')
        {x = 1; p += 4;}
    else if(s[p] == 'F' && s[p + 1] == 'A'){x = 1; p += 5;}
    else if(s[p] >= 'A' && s[p] <= 'Z') x = f[s[p++] - 'A'];

    if(neg) x = 1 - x;
    return x;
}