Cod sursa(job #1204464)

Utilizator tudorv96Tudor Varan tudorv96 Data 2 iulie 2014 23:42:58
Problema Bool Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.63 kb
#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;

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

const int N = 1005;

bool v[26], orFunct(), andFunct(), evalFunct();
int sz, n;
char c[N], s[N], *now;

bool evalFunct() {
    bool val = 0;
    if (*now == 'N' && *(now + 1) == 'O' && *(now + 2) == 'T') {
        now += 3;
        val |= !evalFunct();
    }
    else
        if (*now == 'F' && *(now + 1) == 'A' && *(now + 2) == 'L' && *(now + 3) == 'S' && *(now + 4) == 'E') {
            now += 5;
            val = 0;
        }
    else
        if (*now == 'T' && *(now + 1) == 'R' && *(now + 2) == 'U' && *(now + 3) == 'E') {
            now += 4;
            val = 1;
        }
    else
        if (*now == '(') {
            ++now;
            val = orFunct();
            ++now;
        }
    else {
        val = v[*now - 'A'];
        ++now;
    }
    return val;
}

bool andFunct() {
    bool val = evalFunct();
    while (*now == 'A' && *(now + 1) == 'N' && *(now + 2) == 'D') {
        now += 3;
        val &= evalFunct();
    }
    return val;
}

bool orFunct() {
    bool val = andFunct();
    while (*now == 'O' && *(now + 1) == 'R') {
        now += 2;
        val |= andFunct();
    }
    return val;
}

int main() {
    fin.getline(c, 1005);
    for (int i = 0; i <= strlen(c); ++i)
        if (c[i] != ' ')
            s[sz++] = c[i];
    cout << s << "\n";
    fin >> n;
    fin.get();
    fin.getline(c, n + 1);
    for (int i = 0; i < n; ++i) {
        v[c[i] - 'A'] = !v[c[i] - 'A'];
        now = s;
        fout << orFunct();
    }
}