Cod sursa(job #2583520)

Utilizator Alex18maiAlex Enache Alex18mai Data 18 martie 2020 13:45:02
Problema Bool Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.48 kb
#include <fstream>
#include <string>

using namespace std;

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

bool val[300];
string s;
int i;

bool f1();
bool f2();
bool f3();
bool f4();

bool f1() //OR
{
	bool ans = f2();

	while (i + 3 < s.size() && s[i] == ' ' && s[i + 1] == 'O' && s[i + 2] == 'R' && s[i + 3] == ' ') {
		i += 4;
		ans |= f2();
	}

	return ans;
}

bool f2() //AND
{
	bool ans = f3();

	while (i + 4 < s.size() && s[i] == ' ' && s[i + 1] == 'A' && s[i + 2] == 'N' && s[i + 3] == 'D' && s[i + 4] == ' ') {
		i += 5;
		ans &= f3();
	}

	return ans;

}

bool f3() //NOT
{
	bool ans;

	if (i + 3 < s.size() && s[i] == 'N' && s[i + 1] == 'O' && s[i + 2] == 'T' && s[i + 3] == ' ') {
		i += 4;
		ans = !f3();
	}
	else {
		ans = f4();
	}

	return ans;
}

bool f4() //VALOARE (paranteza, litera, TRUE, FALSE)
{
	bool ans;

	if (s[i] == '(') {
		i++;
		ans = f1();
		i++;
	}
	else if (i + 3 < s.size() && s[i] == 'T' && s[i + 1] == 'R' && s[i + 2] == 'U' && s[i + 3] == 'E') {
		ans = 1;
		i += 4;
	}
	else if (i + 4 < s.size() && s[i] == 'F' && s[i + 1] == 'A' && s[i + 2] == 'L' && s[i + 3] == 'S' && s[i + 4] == 'E') {
		ans = 0;
		i += 5;
	}
	else {
		ans = val[s[i]];
		i++;
	}

	return ans;
}


int main()
{
	
	getline(cin, s);

	int n;
	cin >> n;

	char c;
	while (n--) {
		cin >> c;
		val[c] = !val[c];
		i = 0;
		cout << f1();
	}

	return 0;
}