Pagini recente » Cod sursa (job #1906816) | Cod sursa (job #438584) | Cod sursa (job #2154816) | Cod sursa (job #906736) | Cod sursa (job #2813524)
#include <fstream>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
int n,i;
char c,s[1005];
bool f[26];
bool _or();
bool _and();
bool _exp();
bool _or() {
bool r=_and();
if (s[i]==' ')
i++;
while (s[i]=='O' && s[i+1]=='R') {
i+=2;
r=_and() || r;
}
return r;
}
bool _and() {
bool r=_exp();
if (s[i]==' ')
i++;
while (s[i]=='A' && s[i+1]=='N') {
i+=3;
r=_exp() && r;
}
return r;
}
bool _exp() {
bool r;
if (s[i]==')')
i++;
if (s[i]==' ')
i++;
if (s[i]=='(') {
i++;
r=_or();
i++;
}
else
if (s[i]=='N' && s[i+1]=='O') {
i+=3;
r=!_exp();
}
else
if (s[i]=='T' && s[i+1]=='R') {
r=1;
i+=4;
}
else
if (s[i]=='F' && s[i+1]=='A') {
r=0;
i+=5;
}
else {
r=f[s[i]-'A'];
i++;
}
return r;
}
int main() {
fin.getline(s,sizeof(s));
fin>>n;
while (n--) {
i=0;
fin>>c;
f[c-'A']=!f[c-'A'];
fout<<_or();
}
return 0;
}