Cod sursa(job #2652622)

Utilizator gasparrobert95Gaspar Robert Andrei gasparrobert95 Data 25 septembrie 2020 12:29:03
Problema Bool Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.69 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
map <char, bool> mp;
int n, p;
string s;

bool _or();
bool termen();

bool _and() {
    bool r = _or();
    while (s[p] == 'A' && s[p + 1] == 'N' && s[p + 2] == 'D') {
        p += 4;
        r = r and _or();
        if (s[p] == ' ')
            ++p;
    }
    return r;
}

bool _or() {
    bool r = termen();
    while (s[p] == 'O' && s[p + 1] == 'R') {
        p += 3;
        r = r or termen();
        if (s[p] == ' ')
            ++p;
    }
    return r;
}

bool termen() {
    bool r = false;
    if (s[p] == '(') {
        ++p;
        r = _and();
        if (s[p] == ' ')
            ++p;
    }
    bool _not = false;
    if (s[p] == 'N' && s[p + 1] == 'O' && s[p + 2] == 'T') {
        _not = true;
        p += 3;
        if (s[p] == ' ')
            ++p;
    }
    if (s[p] == 'T' && s[p + 1] == 'R' && s[p + 2] == 'U' && s[p + 3] == 'E') {
        r = true;
        p += 4;
        if (s[p] == ' ')
            ++p;
    }
    if (s[p] == 'F' && s[p + 1] == 'A' && s[p + 2] == 'L' && s[p + 3] == 'S' && s[p + 4] == 'E') {
        p += 5;
        if (s[p] == ' ')
            ++p;
    }
    if (s[p] >= 'A' && s[p] <= 'Z' && (s[p + 1] < 'A' || s[p + 1] > 'Z')) {
        r = mp[s[p]];
        if (s[p] == ' ')
            ++p;
    }
    if (_not)
        r = !r;
    return r;
}

int main() {
    getline(fin, s);
    fin >> n;
    while(n--) {
        char el;
        fin >> el;
        p = 0;
        if (mp[el] == false)
            mp[el] = true;
        else
            mp[el] = false;
        fout << _and();
    }
    return 0;
}