#include<iostream>
#include<string>
#include<queue>
using namespace std;
string s,a;
queue <string> q;
queue <string> ans;
int num;
int main()
{
while(cin>>s)
{
if(s!="true"&&s!="false"&&s!="and"&&s!="or"&&s!="not")
{
cout<<"error";
return 0;
}
if(s=="not")
{
num++;
continue;
}
else
{
if(num>0)
if(s=="or"||s=="and")
{
cout<<"error"<<endl;
return 0;
}
if(num%2==1)
{
if(s=="true") s="false";
else s="true";
}
num=0;
}
q.push(s);
}
if(q.back()=="or"||q.back()=="and")
{
cout<<"error";
return 0;
}
if(q.front()=="or"||q.front()=="and")
{
cout<<"error"<<endl;
return 0;
}
if(q.size()==1)
{
cout<<q.front();
return 0;
}
while(q.size()>=1)
{
if(q.front()=="and")
{
q.pop();
if(q.front()=="or"||q.front()=="and")
{
cout<<"error";
return 0;
}
if(a=="true"&&q.front()=="true")
{
a="true";
}
else
{
a="false";
}
ans.push(a);
q.pop();
}
else
{
ans.push(q.front());
a=q.front();
q.pop();
if(q.size()!=0)
if(ans.back()=="true"||ans.back()=="false")
{
if(q.front()=="true"||q.front()=="false")
{
cout<<"error";
return 0;
}
}
}
}
while(ans.size()>1)
{
if(ans.front()=="or")
{
ans.pop();
if(ans.front()=="or"||ans.front()=="and")
{
cout<<"error";
return 0;
}
if(a=="true"||ans.front()=="true")
{
a="true";
}
else
{
a="false";
}
ans.push(a);
}
else
{
a=ans.front();
ans.pop();
}
}
cout<<ans.front();
return 0;
}
评测地址https://www.luogu.com.cn/record/38671385