Cod sursa(job #3285924)

Utilizator _adeee18Adelina Maria _adeee18 Data 13 martie 2025 16:10:52
Problema Bool Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.65 kb
#include <fstream>
#include <map>

using namespace std;

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

string s, z;
int n, i;

map <char, bool> mp;

bool termen();
bool expresie2();
bool expresie1();

bool termen()
{
    bool r = 0;
    if(s[i] == '(')
    {
        i++;
        r = expresie1();
        i++;
    }
    else if(s[i] == 'N' && s[i + 1] == 'O' && s[i + 2] == 'T')
    {
        i += 3;
        while(s[i] == ' ')
            i++;
        r = !(termen());
    }
    else if(s[i] == 'T' && s[i + 1] == 'R' && s[i + 2] == 'U' && s[i + 3] == 'E')
    {
        i += 4;
        while(s[i] == ' ')
            i++;
        r = 1;
    }
    else if(s[i] == 'F' && s[i + 1] == 'A' && s[i + 2] == 'L' && s[i + 3] == 'S' && s[i + 4] == 'E')
    {
        i += 5;
        while(s[i] == ' ')
            i++;
        r = 0;
    }
    else if(isalpha(s[i]))
    {
        r = mp[s[i]];
        i++;
        while(s[i] == ' ')
            i++;
    }
    return r;
}

bool expresie2()
{
    bool r = termen();
    while(s[i] == 'A' && s[i + 1] == 'N' && s[i + 2] == 'D' )
    {
        i += 3;
        while(s[i] == ' ')
            i++;
        r = (r && termen());
    }
    return r;
}

bool expresie1()
{
    bool r = expresie2();
    while( s[i] == 'O' && s[i + 1] == 'R')
    {
        i += 2;
        while(s[i] == ' ')
            i++;
        r = (r || expresie2());
    }
    return r;
}

int main()
{
    getline(fin, s);
    fin >> n >> z;
    for(int it = 0; it < n; it++)
    {
        mp[z[it]] = !mp[z[it]];
        i = 0;
        fout << expresie1();
    }
    return 0;
}