Pagini recente » Cod sursa (job #357716) | Cod sursa (job #918413) | Cod sursa (job #1918049) | Cod sursa (job #843882) | Cod sursa (job #2453632)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1010;
ifstream fin("bool.in");
ofstream fout("bool.out");
int N, posMax;
int valch[30];
char s[NMAX], v[105];
bool OR();
bool AND();
bool NR();
bool OR(){
bool ans = AND();
while(s[posMax] == 'O' && s[posMax + 1] == 'R'){
posMax += 3;
ans = ans|AND();
}
return ans;
}
bool AND(){
bool ans = NR();
while(s[posMax] == 'A' && s[posMax + 1] == 'N'){
posMax += 4;
ans = ans&NR();
}
return ans;
}
bool NR(){
bool ans = 0;
if(s[posMax] == '('){
posMax++;
ans = OR();
posMax++;
} else if(s[posMax] == 'N' && s[posMax + 1] == 'O'){
posMax += 4;
ans = !NR();
} else if(s[posMax] == 'T' && s[posMax + 1] == 'R'){
posMax += 5;
ans = 1;
} else if(s[posMax] == 'F' && s[posMax + 1] == 'A'){
posMax += 6;
ans = 0;
} else {
ans = valch[s[posMax] - 'A'];
posMax += 2;
}
return ans;
}
int main(){
fin.get(s, NMAX);
fin >> N;
fin.get();
fin.get(v, 105);
for(int i = 0; i < N; i++){
valch[v[i] - 'A'] = 1 - valch[v[i] - 'A'];
posMax = 0;
fout << OR();
}
fin.close();
fout.close();
return 0;
}