Cod sursa(job #2444298)

Utilizator ArkhamKnightyMarcus ArkhamKnighty Data 30 iulie 2019 23:11:29
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <string>

using namespace std;

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

char x[1005], *p;
bool v[27], ev();

bool term()
{
    bool aux=0;
    if(*p=='(')
        p++, aux = ev(), 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 = !term();
    else
        aux = v[*p - 'A'], p += 2;
    return aux;
}
bool fact()
{
    bool aux = term();
    while(*p == 'A' && *(p+1) == 'N')
        p+=4, aux &= term();
    return aux;
}
bool ev()
{
    bool aux = fact();
    while(*p == 'O' && *(p+1) == 'R')
        p += 3, aux |= fact();
    return aux;
}
int main()
{
    int n;
    char ch;

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

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

    return 0;
}