Cod sursa(job #2600880)

Utilizator Katherine456719Swan Katherine Katherine456719 Data 13 aprilie 2020 13:46:18
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.65 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;
ifstream f("bool.in");
ofstream g("bool.out");

char s[1005];
bool val[27];
int ind;
bool f4();
bool f3();
bool f2();
bool f1()
{
    bool raspuns=f2();
     if(s[ind]==' ')
        ++ind;
    while(s[ind]=='O' and s[ind+1]=='R')
    {
        ind+=2;
        raspuns |= f2();
    }
    return raspuns;
}
bool f2()
{
    bool ras=f3();
     if(s[ind]==' ')
        ++ind;
    while(s[ind]=='A' and s[ind+1]=='N' and s[ind+2]=='D')
    {
        ind+=3;
        ras &= f3();
    }
    return ras;
}
bool f3()
{
    bool r=f4();
     if(s[ind]==' ')
        ++ind;
    while(s[ind]=='N' and s[ind+1]=='O' and s[ind+2]=='T')
    {
        ind+=3;
        r =! f3();
    }
    return r;
}
bool f4()
{
    bool raspuns=0;
    if(s[ind]==' ')
        ++ind;
    if(s[ind]=='(')
    {
        ++ind;
        raspuns=f1();
        ++ind;
    }
    else
    {
        if(isalpha(s[ind]) and !isalpha(s[ind+1]))
        {
            raspuns=val[s[ind]-'A'];
            ++ind;
        }
        else if(s[ind]=='T' and s[ind+1]=='R' and s[ind+2]=='U' and s[ind+3]=='E')
        {
            ind+=4;
            raspuns=1;
        }
        else if(s[ind]=='F' and s[ind+1]=='A' and s[ind+2]=='L' and s[ind+3]=='S' and s[ind+4]=='E')
        {
            ind+=5;
            raspuns=0;
        }
    }
    return raspuns;
}
int main()
{
    int n;
    f.getline(s,1005);
    f>>n;
    char c;
    for(int i=0; i<n; i++)
    {
        ind=0;
        f>>c;
        val[c-'A']=!val[c-'A'];
        g<<f1();
    }
    return 0;
}