Pagini recente » Cod sursa (job #2445033) | Cod sursa (job #3261839) | Cod sursa (job #1585478) | Cod sursa (job #3032168) | Cod sursa (job #2412727)
#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;
ifstream si("bool.in");
ofstream so("bool.out");
int fr[30];
char exp[1010], *p=exp, c;
int n;
bool _and();
bool term();
bool _or();
bool term() {
bool rez=0;
if(*p=='(') {
p++;
rez=_or();
p++;
}
else {
if(*p=='N'&&*(p+1)=='O') {
p+=4;
rez=!term();
}
else {
if(*p=='T'&&*(p+1)=='R') {
p+=5;
rez=1;
}
else {
if(*p=='F'&&*(p+1)=='A') {
p+=6;
rez=0;
}
else {
if(isalpha(*p)) {
rez=fr[*p-'A'];
p+=2;
}
else
p+=2;
}
}
}
}
return rez;
}
bool _and() {
bool r=term();
while(*p=='A'&&*(p+1)=='N') {
p+=4;
r=r&term();
}
return r;
}
bool _or() {
bool r=_and();
while(*p=='O'&&*(p+1)=='R') {
p+=3;
r=r|_and();
}
return r;
}
int main() {
si.getline(exp,1000);
si>>n;
si.get();
for(int i=1; i<=n; i++) {
si>>c;
fr[c-'A']=!fr[c-'A'];
p=exp;
so<<_or();
}
return 0;
}