Pagini recente » Cod sursa (job #2450196) | Cod sursa (job #2043733) | Cod sursa (job #2148498) | Cod sursa (job #3139648) | Cod sursa (job #1651900)
#include <fstream>
#include <iostream>
using namespace std;
int l, i, n, j;
string s, c, ch;
bool v[30];
bool term(), fact();
//(NOT (NOT G OR F)) AND (NOT J)
//(!(!G|F))&(!J)
//(NOT (G OR (B AND R) OR F)) AND (NOT J)
//(NOT (NOT (T AND A)) OR ((L) AND (O) OR NOT U))
bool expr () { //(!(!(T&A))|((L)&(O)|!U))
bool sol = term();
while (ch[i] == '|') {
i++;
bool sol2 = term();
sol = sol or sol2;
}
return sol;
}
bool term () {//(!(!(T&A))|((L)&(O)|!U))
bool sol = fact();
while (ch[i] == '&') {
i++;
bool sol2 = fact();
sol = sol and sol2;
}
return sol;
}
bool fact () { //(!(!(T&A))|((L)&(O)|!U))
bool sol = false;
if (ch[i] == '!') {
i++;
sol = not fact();
}
else {
if (ch[i] == '(') {
i++;
sol = expr();//i++;
if (ch[i] == ')')
i++;
}
else {
sol = v[ch[i]-'A'+1];
i++;
}
}
return sol;
}
int main () {
string s;
ifstream fi("bool.in");
ofstream fo("bool.out");
getline(fi, s); fi >> n; fi.get(); fi >> c;
l = s.length()-1; v[27] = 1;
for (i = 0; i <= l-1; i++) {
if (s[i] == ' ')
s.erase(i, 1);
if (s[i] == 'A' and s[i+1] == 'N')
s[i] = '&', s.erase(i+1, 2);
if (s[i] == 'N' and s[i+1] == 'O')
s[i] = '!', s.erase(i+1, 2);
if (s[i] == 'O' and s[i+1] == 'R')
s[i] = '|', s.erase(i+1, 1);
if (s[i] == 'T' and s[i+1] == 'R')
s[i] = '[', s.erase(i+1, 3);
if (s[i] == 'F' and s[i+1] == 'A')
s[i] = '\\', s.erase(i+1, 4);
}
for (j = 0; j <= n-1; j++) {
v[c[j]-'A'+1] ? v[c[j]-'A'+1] = false : v[c[j]-'A'+1] = true;
i = 0; ch = s;
fo << (bool)expr();
}
return 0;
}