#include<bits/stdc++.h>
using namespace std;
string n;
int ans1,ans2,ans;
string ToExpr(string s){
stack<char> st;int len=s.size();
string ans="";
for(int i=0;i<len;i++){
if(s[i]=='1' || s[i]=='0') ans+=s[i];
else if(s[i]=='(') st.push(s[i]);
else if(s[i]==')'){
while(st.top()!='(' && !st.empty()){
ans+=st.top();
st.pop();
}
st.pop();
}
else if(s[i]=='|'){
char c;
while(!st.empty() && st.top()=='&'){
ans+=st.top();
st.pop();
}
st.push('|');
}
else st.push(s[i]);
}
while(!st.empty()) ans+=st.top(),st.pop();
return ans;
}
struct node{
int num,o,a;
};
int main(){
cin>>n;
n=ToExpr(n);
//cout<<n<<endl;
stack<node> st;
int len=n.size();
for(int i=0;i<len;i++){
if(n[i]=='|'){
node aa=st.top();st.pop();
node bb=st.top();st.pop();
st.push({aa.num|bb.num,
bb.o+(bb.num==1?1:aa.o),
bb.a+(bb.num==1?0:aa.a)});
}
else if(n[i]=='&'){
node aa=st.top();st.pop();
node bb=st.top();st.pop();
st.push({aa.num&bb.num,
bb.o+(bb.num==0?0:aa.o),
bb.a+(bb.num==0?1:aa.a)});
}
else st.push({n[i]-'0',0,0});
}
cout<<st.top().num<<endl<<st.top().a<<" "<<st.top().o;
return 0;
}
思路和这个视频的一样,卡了快一个半小时20pts了,找不出哪的问题...