Pagini recente » Cod sursa (job #2403560) | Cod sursa (job #2264666) | Cod sursa (job #1626696) | Cod sursa (job #950677) | Cod sursa (job #2984261)
#include<bits/stdc++.h>
using namespace std;
ifstream in("bool.in");
ofstream out("bool.out");
char t[1005],s[1005],c;
int i,k,n;
bool F[130];
int op_or();
int op_and();
int op_xor();
int factor();
void transforma();
int main(){
in.get(s,1002);
in.get();
transforma();
in>>n;
for(int j=1;j<=n;j++){
in>>c;
F[c]=!F[c];
i=0;
out<<op_or();
}
}
int op_or(){
int r=op_and();
while(t[i]=='|'){
i++;
r=(r | op_and());
}
return r;
}
int op_and(){
int r=op_xor();
while(t[i]=='&'){
i++;
r=(r & op_xor());
}
return r;
}
int op_xor(){
int r=factor();
while(t[i]=='^'){
i++;
r=(r^factor());
}
return r;
}
int factor(){
int r;
if(t[i]=='('){
i++;
r=op_or();
i++;
}
else{
if(t[i]=='0'){
i++;
return 0;
}
if(t[i]=='1'){
i++;
return 1;
}
return F[(int)(t[i++])];
}
return r;
}
void transforma(){
for(i=0;s[i]!=0;i++){
if(s[i]==' ')
continue;
if(s[i]=='(' || s[i]==')'){
t[k++]=s[i];
continue;
}
if(s[i]== 'T' && s[i+1]=='R'){
t[k++]='1';
i=i+3;
continue;
}
if(s[i]=='F' && s[i+1]=='A'){
t[k++]='0';
i=i+4;
continue;
}
if(s[i]=='A'&& s[i+1]=='N'){
t[k++]='&';
i=i+2;
continue;
}
if(s[i]=='O' && s[i+1]=='R'){
t[k++]='|';
i++;
continue;
}
if(s[i]=='N' && s[i+1]=='O'){
t[k++]='1';
t[k++]='^';
i=i+2;
continue;
}
t[k++]=s[i];
}
}