Cod sursa(job #2637491)

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

using namespace std;

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

bool orr() ;
bool andd() ;
bool nott() ;

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

bool nott()
{

    bool aux = 0 ;

    if (*p == '(')
        p ++, aux = orr(), 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 = !nott() ;

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

    return aux ;

}

bool andd()
{

    bool aux = nott() ;

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

    return aux ;

}

bool orr()
{

    bool aux = andd() ;

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

    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 << orr() ;

    return 0;

}