Cod sursa(job #2444295)

Utilizator ArkhamKnightyMarcus ArkhamKnighty Data 30 iulie 2019 23:05:07
Problema Bool Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>
#include <string>

using namespace std;

ifstream cin("bool.in");
ofstream cout("bool.out");

char s[1005], *p;
bool v[27];
bool eval();

bool termen()
{
    bool aux = 0;
    if(*p == '(')
        p++, aux = eval(), p++;
    else if(*p == 'F' && *p == 'A')
        p += 6, aux = 0;
    else if(*p == 'T' && *p == 'R')
        p += 5, aux = 1;
    else if(*p == 'N' && *(p + 1) == 'O')
        p += 4, aux = !eval();
    else aux = v[*p - 'A'], p += 2;
   ;
    return aux;
}
bool produs()
{
    bool aux = termen();

    while(*p == 'A' && *(p + 1) == 'N')
        p = p + 4, aux &= termen();

    return aux;
}

bool eval()
{
    bool aux = produs();

    while(*p == 'O' && *(p + 1) == 'R')
        p += 3, aux |= produs();

    return aux;
}

int main()
{
    int n;
    char c;

    cin.getline(s,1005);
    cin >> n;
    for(int i = 1 ; i <= n ; i++)
    {
        cin >> c;
        v[c-'A'] = !v[c - 'A'];
        p = s;
        cout << eval();
    }
    return 0;
}