Cod sursa(job #2862267)

Utilizator matei.tudoseMatei Tudose matei.tudose Data 5 martie 2022 10:46:09
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <fstream>
#include <cstring>
#include <iostream>
using namespace std;

ifstream fin("bool.in");
ofstream fout("bool.out");

char s[1501], modific[105];
int n, poz, size;
bool val[128];


bool si();
bool eval();

bool sau()
{
    bool rez = si();
    while (s[poz] == 'O' && s[poz + 1] == 'R')
    {
        poz += 3;
        rez = rez | si();
    }
    return rez;
}

bool si()
{
    bool rez = eval();
    while (s[poz] == 'A' && s[poz + 1] == 'N' && s[poz + 2] == 'D')
    {
        poz += 4;
        rez = rez & eval();
    }
    return rez;
}

bool eval()
{
    bool rez;
    if (s[poz] == '(')
    {
        poz++;
        rez = sau();
        poz++;
    }
    else if (s[poz] == 'N' && s[poz + 1] == 'O' && s[poz + 2] == 'T')
    {
        poz += 4;
        rez = !eval();
    }
    else if (s[poz] == 'F' && s[poz + 1] == 'A' && s[poz + 2] == 'L' && s[poz + 3] == 'S' && s[poz + 4] == 'E')
    {
        poz += 6;
        rez = 0;
    }
    else if (s[poz] == 'T' && s[poz + 1] == 'R' && s[poz + 2] == 'U' && s[poz + 3] == 'E')
    {
        poz += 5;
        rez = 1;
    }
    else
    {
        rez = val[s[poz]];
        poz += 2;
    }
    return rez;
}

int main()
{
    fin.getline(s, 1501);
    fin >> n;
    for (int i = 1; i <= n; i++)
        fin >> modific[i];
    size = strlen(s);
    for (int i = 1; i <= n; i++)
    {
        val[modific[i]] = !val[modific[i]];
        poz = 0;
        fout << sau();
    }
    return 0;
}