Pagini recente » Cod sursa (job #870977) | Cod sursa (job #1919932) | Cod sursa (job #376416) | Cod sursa (job #1244477) | Cod sursa (job #878829)
Cod sursa(job #878829)
#include <fstream>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
const int sigma= 26;
const int nmax= 100, lmax= 1111;
char v[lmax+2];
char ch[nmax+2];
bool b[sigma];
int m, ind;
void inc(int x){
for (ind+= x; ind<m&& v[ind]==' '; ++ind){
}
}
bool op_or(){
if (ind+1<m&& v[ind]=='O'&& v[ind+1]=='R'){
inc(2);
return 1;
}else{
return 0;
}
}
bool op_and(){
if (ind+2<m&& v[ind]=='A'&& v[ind+1]=='N'/*&& v[ind+2]=='D'*/){
inc(3);
return 1;
}else{
return 0;
}
}
bool op_not(){
if (ind+2<m&& v[ind]=='N'&& v[ind+1]=='O'/*&& v[ind+2]=='T'*/){
inc(3);
return 1;
}else{
return 0;
}
}
bool op_true(){
if (ind+3<m&& v[ind]=='T'&& v[ind+1]=='R'/*&&
v[ind+2]=='U'&& v[ind+3]=='E'*/){
inc(4);
return 1;
}else{
return 0;
}
}
bool op_false(){
if (ind+4<m&& v[ind]=='F'&& v[ind+1]=='A'/*&&
v[ind+2]=='L'&& v[ind+3]=='S'&& v[ind+4]=='E'*/){
inc(5);
return 1;
}else{
return 0;
}
}
bool term(), expr_and(), expr_or();
bool term(){
if (ch[ind]=='('){
inc(1);
bool x= expr_or();
inc(1);
return x;
}else if (op_not()){
return !term();
}else if (op_true()){
return 1;
}else if (op_false()){
return 0;
}else{
int x= b[v[ind]-'A'];
inc(1);
return x;
}
}
bool expr_and(){
bool x= term();
while (op_and()){
x&= term();
}
return x;
}
bool expr_or(){
bool x= expr_and();
while (op_or()){
x|= expr_and();
}
return x;
}
int main(){
fin.getline(v, lmax+2);
int n;
fin>>n;
fin.getline(ch, 2);
fin.getline(ch, nmax+2);
for (int m= 0; m<=lmax&& v[m]!='\n'; ++m){
}
for (int i= 0; i<n; ++i){
b[ch[i]-'A']^= 1;
ind= 0;
fout<<expr_or();
}
fout<<"\n";
return 0;
}