Cod sursa(job #3271709)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 27 ianuarie 2025 06:40:17
Problema Bool Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>

using namespace std;

const int NMAX = 1001;

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

bool alf[30], expresie(), termen(), factor();
char *p;

bool expresie()
{
    bool crt = termen();
    while(*p == 'O') p += 3, crt = crt || termen();
    return crt;
}

bool termen()
{
    bool crt = factor();
    while(*p == 'A') p += 4, crt = crt && factor();
    return crt;
}

bool factor()
{
    bool crt, neg = 0;
    if(*p == 'N' && *(p + 1) == 'O') p += 4, neg = 1;
    if(*p == '(') ++p, crt = expresie(), ++p;
    else if(*p == 'T' && *(p + 1) == 'R') crt = 1, p += 4;
    else if(*p == 'F' && *(p + 1) == 'A') crt = 0, p += 5;
    else crt = alf[*p - 'A'], ++p;
    if(*p == ' ') ++p;
    else if(*(p + 1) == ' ') p += 2;
    return (neg ? !crt : crt);
}

int main()
{
    char s[NMAX];
    fin.getline(s, NMAX);
    int n;
    char c;
    fin >> n;
    while(n--)
    {
        fin >> c;
        alf[c - 'A'] = !alf[c - 'A'];
        p = s;
        fout << expresie();
    }
    return 0;
}