Cod sursa(job #567090)

Utilizator darrenRares Buhai darren Data 29 martie 2011 18:33:47
Problema Bool Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <cctype>
#include <fstream>

using namespace std;

int N;
bool stare[26];
char E[1005], *now, aux[105];

int Eval()
{
    bool result = false, wait = false, numnow, negate, oper = false;

    while (true)
    {
        if (*now == ' ') ++now;

        negate = false;
        while (*now == 'N')
        {
            negate = !negate, now += 3;
            if (*now == ' ') ++now;
        }

        if (*now == '(') ++now, numnow = Eval();
        else numnow = stare[*now - 'A'], ++now;

        if (negate) numnow = !numnow;

        if (oper == false) result |= wait, wait = numnow;
        else               wait &= numnow;

        if (*now == ')' || *now == '\0')
        {
            ++now;
            break;
        }

        if (*now == ' ' ) ++now;
        if (*now == 'O') oper = false, now += 2;
        else             oper = true, now += 3;
    }

    result |= wait;

    return result;
}

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

    fin.getline(E, 1005);
    fin >> N;

    fin.getline(aux, 5);
    fin.getline(aux, 105);

    for (int i = 0; i < N; ++i)
    {
        stare[aux[i] - 'A'] = !stare[aux[i] - 'A'];
        now = E;

        fout << Eval();
    }

    fin.close();
    fout.close();
}