Pagini recente » Cod sursa (job #1379754) | Cod sursa (job #1331620) | Cod sursa (job #2199589) | Cod sursa (job #1814736) | Cod sursa (job #876678)
Cod sursa(job #876678)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
#define MAXLIT 200
int val[MAXLIT], poz;
string s;
bool solveAND();
bool solveNUMBER();
bool solveOR() {
int sol = solveAND();
while (poz < s.size() && s.substr(poz, 2) == "OR") {
poz += 3;
sol |= solveAND();
}
return sol;
}
bool solveAND() {
int sol = solveNUMBER();
while (poz < s.size() && s.substr(poz, 3) == "AND") {
poz += 4;
sol &= solveNUMBER();
}
return sol;
}
bool solveNUMBER() {
if (s.substr(poz, 4) == "TRUE") {
poz += 5;
return 1;
}
if (s.substr(poz, 5) == "FALSE") {
poz += 6;
return 0;
}
int schimba = 0, rez;
if (s.substr(poz, 3) == "NOT") {
poz += 4;
schimba = 1;
}
if (s[poz] == '(') {
poz += 1;
rez = solveOR();
poz += 1;
}
else {
rez = val[s[poz]];
poz += 2;
}
if (schimba)
rez = !rez;
return rez;
}
int main() {
int nrMod;
char c;
getline(fin, s);
fin >> nrMod;
for (int i = 1; i <= nrMod; ++i) {
fin >> c;
val[c] = !val[c]; poz = 0;
fout << solveOR();
}
return 0;
}