Cod sursa(job #2074272)

Utilizator jumareastefanstefan jumarea jumareastefan Data 24 noiembrie 2017 12:42:54
Problema Bool Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <iostream>
#include <fstream>
#include <cstdio>

using namespace std;

char s[10001], *p, c;
bool v[30], a;
int n, z;

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

bool eval();
bool term();
bool fact();

int main()
{
    f.getline(s, 10000);
    //f>>c;
    //while(c!='\n'){s[z++]=c;f>>c;}
    f>>n;
    for (int j=1; j<=n; j++)
        v[j]=true;
    for (int j=1; j<=n; j++)
    {
        f>>c;
        v[c-'A']=!v[c-'A'];
        p=s;
        a=eval();
        //if (a) g<<"1";
        //else g<<"0";
        g<<a;
    }
}

bool eval()
{
    bool r=term();
    while (*p=='O' && *(p+1)=='R')
    {
        p+=3;
        r=r | term();
    }
    return r;
}
bool term()
{
    bool r=fact();
    while (*p=='A' && *(p+1)=='N')
    {
        p+=4;
        r=r&fact();
        //else {++p; r=r/fact();
    }
    return r;
}

bool fact()
{
    bool r=false;
    if (*p=='(')
    {
        p++;
        r=eval();
        p++;
    }
    else if(*p=='T' && *(p+1)=='R')
    {
        r=true;
        p+=5;
    }
    else if (*p=='F' && *(p+1)=='A')
    {
        r=false;
        p+=6;
    }
    else if (*p=='N' && *(p+1)=='O')
    {
        p+=4;
        r=!fact();
    }
    else
    {
        if (v[*p-'A']==false) r=false;
        else r=true;
        p+=2;
    }

    return r;
}