WA了第十个
#include<bits/stdc++.h>
using namespace std;
string a[10000];
map<string,string>m;
int f(int w){
w++;
while(a[w]==" "){
w++;
}
return w;
}
int f1(int w){
w--;
while(a[w]==" "){
w--;
}
return w;
}
int main(){
m["true"]="false";
m["false"]="true";
int n=1;
while(cin>>a[n]){
n++;
}
n--;
int tem=0;
int x;
if(a[1]=="or"||a[1]=="and"||a[n]=="or"||a[n]=="and"||a[n]=="not"){
cout<<"error";
return 0;
}
for(int i=1;i<=n;i++){
if(a[i]=="not"){
if(tem==0){
tem=1;
x=i;
}
else{
tem=0;
a[x]=" ";
a[i]=" ";
}
if(a[f(i)]=="or"||a[f(i)]=="and"){
cout<<"error";
return 0;
}
}
}
if(tem==1){
a[f(x)]=m[a[f(x)]];
a[x]=" ";
}
for(int i=1;i<=n;i++){
if(a[i]=="and"){
if(a[f(i)]=="or"||a[f(i)]=="and"){
cout<<"error";
}
if(a[f1(i)]=="true"&&a[f(i)]=="true"){
a[i]="true";
a[f1(i)]=" ";
a[f(i)]=" ";
}
else{
a[i]="false";
a[f1(i)]=" ";
a[f(i)]=" ";
}
}
}
for(int i=1;i<=n;i++){
if(a[i]=="or"){
if(a[f(i)]=="or"){
cout<<"error";
}
if(a[f1(i)]=="false"&&a[f(i)]=="false"){
a[i]="false";
a[f1(i)]=" ";
a[f(i)]=" ";
}
else{
a[i]="true";
a[f1(i)]=" ";
a[f(i)]=" ";
}
}
}
int www=-1;
for(int i=1;i<=n;i++){
if(a[i]!=" "&&www==-1){
www=i;
}
else if(a[i]!=" "&&www!=-1){
cout<<"error";
return 0;
}
}
if(www==-1){
cout<<"error";
return 0;
}
cout<<a[www];
return 0;
}