不是求调。本地能过,OJ上RE。求RE可能的原因。
#include<bits/stdc++.h>
using namespace std;
char s[1000005];
int len,w[125];
stack<int> s1;
stack<char> s2;
void calc(){
char ch=s2.top();
s2.pop();
if(ch=='!'){
s1.top()^=1;
return;
}
int x=s1.top();
s1.pop();
if(ch=='&') s1.top()&=x;
else if(ch=='|') s1.top()|=x;
}
signed main(){
freopen("boolean.in","r",stdin);
freopen("boolean.out","w",stdout);
scanf("%s",s+1);
len=strlen(s+1);
w['|']=1,w['&']=2,w['!']=3;
for(int i=1;i<=len;i++){
if(s[i]==' ') continue;
if(s[i]=='F') s1.push(0);
else if(s[i]=='V') s1.push(1);
else if(s[i]==')'){
while(s2.top()!='(') calc();
s2.pop();
}else if(s[i]=='('||s[i]=='!') s2.push(s[i]);
else{
while(s2.size()&&w[s[i]]<=w[s2.top()]) calc();
s2.push(s[i]);
}
}
while(s2.size()) calc();
if(s1.top()) puts("V");
else puts("F");
return 0;
}