Cod sursa(job #2950917)

Utilizator AswVwsACamburu Luca AswVwsA Data 4 decembrie 2022 20:29:19
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.92 kb
//nu mai pot, deci nu mai pot.... :(((((
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

//expresie = termen si termen si termen...
//termen = ceva sau ceva sau ceva...
//ceva = litera, expresie sau constanta sau not de ceva
bool f['z' - 'a' + 3];
char s[1003];
char aux[1003];

bool expresie();
bool termen();
bool ceva();
int i;

bool expresie()
{
    bool ans = termen();
    while (s[i] == 'O' and s[i + 1] == 'R')
    {
        i += 2;
        ans |= termen();
    }
    return ans;
}

bool termen()
{
    bool ans = ceva();
    while (s[i] == 'A' and s[i + 1] == 'N' and s[i + 2] == 'D')
    {
        i += 3;
        ans &= ceva();
    }
    return ans;
}
bool ceva()
{
    bool ans;
    if (s[i] == '(')
    {
        i++;
        ans = expresie();
        i++;
    }
    else if (s[i] == 'F' and s[i + 1] == 'A' and s[i + 2] == 'L')
    {
        ans = 0;
        i += 5;
    }
    else if (s[i] == 'T' and s[i + 1] == 'R')
    {
        ans = 1;
        i += 4;
    }
    else if (s[i] == 'N' and s[i + 1] == 'O' and s[i + 2] == 'T')
    {
        i += 3;
        ans = !ceva();
    }
    else if (isalpha(s[i]))
    {
        ans = f[s[i] - 'A'];
        i++;
    }
    return ans;
}
int main()
{
    ifstream cin("bool.in");
    ofstream cout("bool.out");
    /*
    ((NOT (J) AND (X)) AND (NOT (B AND U)) AND NOT (NOT ((R) OR (D)))) OR (NOT (NOT (T AND A)) OR ((L) AND (O) OR NOT U))
    100
    GPTGVCEKKRKZXBKDWGCZSMRTRUYEIVGYDGOMIMJNZJZUBJWCDNPPLTXSCQYMJJMFZPUDQFJCSWDQOXZWKQLDWHBLTWSUMMYEEZVY
    */
    cin.getline(aux, sizeof(aux));
    for (int j = 0; aux[j]; j++)
        if (aux[j] != ' ')
            s[i++] = aux[j];
    int n;
    cin >> n;
    while (n--)
    {
        char x;
        cin >> x;
        f[x - 'A'] ^= 1;
        i = 0;
        //cout << "gg";
        cout << expresie();
    }
    return 0;
}