Cod sursa(job #2436887)

Utilizator PatrickCplusplusPatrick Ondreovici PatrickCplusplus Data 7 iulie 2019 15:21:07
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.59 kb
#include <bits/stdc++.h>

using namespace std;

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

char expresie[1010], v[110];
int val[50];
int n, p;

bool IsOr();
bool IsAnd();
bool GetVar();

bool IsOr()
{
    bool r = IsAnd();
    while (expresie[p] == 'O' && expresie[p + 1] == 'R')
    {
        p = p + 3;
        r = r|IsAnd();
    }
    return r;
}

bool IsAnd()
{
    bool r = GetVar();
    while (expresie[p] == 'A' && expresie[p + 1] == 'N' && expresie[p + 2] == 'D')
    {
        p = p + 4;
        r = r&GetVar();
    }
    return r;
}

bool GetVar()
{
    bool r = false;
    if (expresie[p] == 'N' && expresie[p + 1] == 'O' && expresie[p + 2] == 'T')
    {
        p = p + 4;
        r = !GetVar();
    }
    else if (expresie[p] == '(')
    {
        p = p + 1;
        r = IsOr();
        p = p + 1;
    }
    else if (expresie[p] == 'T' && expresie[p + 1] == 'R' && expresie[p + 2] == 'U' && expresie[p + 3] == 'E')
    {
        p = p + 5;
        r = true;
    }
    else if (expresie[p] == 'F' && expresie[p + 1] == 'A' && expresie[p + 2] == 'L' && expresie[p + 3] == 'S' && expresie[p + 4] == 'E')
    {
        p = p + 6;
        r = false;
    }
    else
    {
        r = val[expresie[p] - 'A'];
        p = p + 2;
    }
    return r;
}

int main()
{
    fin.get(expresie, 1005);
    fin >> n;
    fin.get();
    fin.get(v, 105);
    for (int i = 0; i < strlen(v); ++i)
    {
        val[v[i] - 'A'] = 1 - val[v[i] - 'A'];
        p = 0;
        fout << IsOr();
    }
    fin.close();
    fout.close();
    return 0;
}