#include #include #include #include #include #include #include #include #include #include using namespace std; int n; string expr=""; string postfix=""; map mp; map mp1; vector available; bool cmp(string a,string b) { if(a.length()>b.length()) { return false; } else if(a.length()b[0]) return false; else return true; } char operat[]={'&','|','!'}; bool isOperator(char a) { for(int i=0;i<3;i++) { if(a==operat[i]) return true; } return false; } bool isOperator(string a) { for(int i=0;i<3;i++) { if(a[0]==operat[i]) return true; } return false; } int len; string getNum(int from,int &to) { string num=""; int i; int sign=0; for(i=from;i stk; int sign=0; for(int i=st;i1) i--; } else if(expr[i]=='&') { if(stk.size()&&stk.top()=='&') { pstfx+=" &"; } else { stk.push('&'); } } else if(expr[i]=='|') { if(stk.size()&&stk.top()=='|') { pstfx+=" |"; } else if(stk.size()&&stk.top()=='&') { while(stk.size()&&stk.top()=='&') { stk.pop(); pstfx+=" &"; } if(stk.size()&&stk.top()=='|') pstfx+=" |"; else stk.push('|'); } else { stk.push('|'); } } } else { int e; string num=getNum(i,e); pstfx+=" "+num; while(sign) { pstfx+=" !"; sign--; } i=e; } } while(stk.size()) { char c=stk.top(); stk.pop(); pstfx+=" "; pstfx+=c; } return pstfx; } bool evaluate(int z,bitset<10> val) { int y=0; int temp=z; stack stk; stringstream ss(postfix); string x; int pos1,pos2; int v1,v2,res; string s1,s2; char t[5]; while(ss>>x) { if(isOperator(x)) { switch(x[0]) { case '|': s1=stk.top(); stk.pop(); s2=stk.top(); stk.pop(); if(s1[0]=='x') { s1=s1.substr(1,s1.length()); pos1=val[mp[s1]]; } else { sscanf(s1.c_str(),"%d",&pos1); } if(s2[0]=='x') { s2=s2.substr(1,s2.length()); pos2=val[mp[s2]]; } else { sscanf(s2.c_str(),"%d",&pos2); } res=pos1|pos2; sprintf(t,"%d",res); stk.push(string(t)); break; case '&': s1=stk.top(); stk.pop(); s2=stk.top(); stk.pop(); if(s1[0]=='x') { s1=s1.substr(1,s1.length()); pos1=val[mp[s1]]; } else { sscanf(s1.c_str(),"%d",&pos1); } if(s2[0]=='x') { s2=s2.substr(1,s2.length()); pos2=val[mp[s2]]; } else { sscanf(s2.c_str(),"%d",&pos2); } res=pos1&pos2; sprintf(t,"%d",res); stk.push(string(t)); break; case '!': string s1=stk.top(); stk.pop(); if(s1[0]=='x') { s1=s1.substr(1,s1.length()); pos1=val[mp[s1]]; } else { sscanf(s1.c_str(),"%d",&pos1); } res=!pos1; sprintf(t,"%d",res); stk.push(string(t)); break; } // cout<>n; char c; while((c=getchar())!=EOF) { if(c!=' '&&c!='\t'&&c!='\n') expr+=c; } int end; len=expr.length(); postfix=toPostfix(0,end); // cout<=0;i--) { bitset<10> val((unsigned long)i); if(!evaluate(i,val)) { cout<<"NO"<>n; return 0; }