Cod sursa(job #2637492)

Utilizator LORDENVraja Luca LORDEN Data 23 iulie 2020 12:06:50
Problema Bool Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>
#include <string>

using namespace std;

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

bool eval() ;
bool fact() ;
bool termen() ;

int n ;
char x[1005], *p ;
bool v[27] ;

bool termen()
{

    bool aux = 0 ;

    if (*p == '(')
        p ++, aux = eval(), p ++ ;

    else if (*p == 'F' && *(p + 1) == 'A')
        p += 6, aux = 0 ;

    else if (*p == 'T' && *(p + 1) == 'R')
        p += 5, aux = 1 ;

    else if (*p == 'N' && *(p + 1) == 'O')
        p += 4, aux = !termen() ;

    else
        aux = v[*p - 'A'], p += 2 ;

    return aux ;

}

bool fact()
{

    bool aux = termen() ;

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

    return aux ;

}

bool eval()
{

    bool aux = fact() ;

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

    return aux ;

}

int main()
{

    int car = 0 ;

    cin.getline(x, 1005) ;
    cin >> n ;

    for (int i = 1 ; i <= n ; i ++)
        cin >> car, v[car - 'A'] = !v[car - 'A'], p = x, cout << eval() ;

    return 0;

}