Cod sursa(job #2436879)

Utilizator PatrickCplusplusPatrick Ondreovici PatrickCplusplus Data 7 iulie 2019 14:58:26
Problema Bool Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <bits/stdc++.h>

using namespace std;

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

int z, n, v[300], p = 0;
char e[2009];
string x;

bool eval();

bool eval2();

bool eval3();


bool eval()
{
    bool r = eval2();
    while (e[p] == 'O' && e[p + 1] == 'R')
    {
        p = p + 2;
        while (e[p] == ' ') ++p;
        r = r || eval2();
    }
    return r;
}

bool eval2()
{
    bool r = eval3();
    while (e[p] == 'A' && e[p + 1] == 'N' && e[p + 2] == 'D')
    {
        p = p + 3;
        while (e[p] == ' ') ++p;
        r = r && eval2();
    }
    return r;
}

bool eval3()
{
    bool r;
    if (e[p] == 'N' && e[p + 1] == 'O' && e[p + 2] == 'T')
    {
        p = p + 3;
        while (e[p] == ' ') ++p;
        r = !eval3();
        p = p + 1;
        while (e[p] == ' ') ++p;
    }
    else if (e[p] == 'T' && e[p + 1] == 'R' && e[p + 2] == 'U' && e[p + 3] == 'E')
    {
        p = p + 4;
        while (e[p] == ' ') ++p;
        r = true;
    }
    else if (e[p] == 'F' && e[p + 1] == 'A' && e[p + 2] == 'L' && e[p + 3] == 'S' && e[p + 4] == 'E')
    {
        p = p + 5;
        while (e[p] == ' ') ++p;
        r = false;
    }
    else if (e[p] == '(')
    {
        ++p;
        r = eval();
    }
    else
    {
        r = v[e[p]];
    }
    return r;
}


int main()
{
    fin.get(e, 2001);
    fin >> n;
    fin >> x;
    for (int i = 1; i <= n; ++i)
    {
        v[x[i - 1]] = !v[x[i - 1]];
        p = 0;
        fout << eval();
    }
    fin.close();
    fout.close();
}