rt,题号是P8815,这是代码,只有20分,剩下的都是RE,我把点下下来放到本地运行他输出了正确答案后才RE,挺奇怪的
#include <bits/stdc++.h>
using namespace std;
string st,s;
stack<char>c;
stack<int>k1,k2,k3;
int t1,t2,tk1,tk2,tk3,tk4,cnt;
//k1表示结果,k2表示|短路次数,k3表示&短路次数
int first(char x){
if(x=='|')return 0;
if(x=='&')return 1;
return -1;
}
int main(){
cin>>st;
for(int i=0;i<st.size();i++){
char v=st[i];
if(v=='0'||v=='1')s[++cnt]=v;
else if(v==')'){
while(c.size()&&c.top()!='('){
s[++cnt]=c.top();
c.pop();
}
c.pop();
}else if(v!='('){
while(c.size()&&first(c.top())>=first(v)){
s[++cnt]=c.top();
c.pop();
}
c.push(v);
}else c.push(v);
}
while(c.size()){
s[++cnt]=c.top();
c.pop();
}
for(int i=1;i<=cnt;i++){
if(s[i]=='0'||s[i]=='1'){
k1.push(s[i]-'0');
k2.push(0);
k3.push(0);
}else{
//结果
t2=k1.top();
k1.pop();
t1=k1.top();
k1.pop();
//|短路次数
tk2=k2.top();
k2.pop();
tk1=k2.top();
k2.pop();
//&短路次数
tk4=k3.top();
k3.pop();
tk3=k3.top();
k3.pop();
if(s[i]=='&'){
if(t1==0){//&短路
k1.push(0);
k2.push(tk1);
k3.push(tk3+1);
}else{
k1.push(t1&t2);
k2.push(tk1+tk2);
k3.push(tk3+tk4);
}
}else{
if(t1==1){
k1.push(1);
k2.push(tk1+1);
k3.push(tk3);
}else{
k1.push(t1|t2);
k2.push(tk1+tk2);
k3.push(tk3+tk4);
}
}
}
}
cout<<k1.top()<<endl<<k3.top()<<' '<<k2.top()<<endl;
return 0;
}
,```