记录https://www.luogu.com.cn/record/76303907
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
bool ans, f, A, o, b, c, d;
int x, y;
string a;
stack <bool> s;
int main()
{
while(cin >> a)
{
if(a == "not")
{
if(f)
{
f = false;
continue;
}
if(!f)
{
f = true;
continue;
}
}
else if(a == "and")
{
A = true;
x = 0;
y++;
}
else if(a == "or")
{
x = 0;
y++;
}
else if(a == "true" && !f)
{
s.push(true);
x++;
y = 0;
}
else if(a == "false" && !f)
{
s.push(false);
x++;
y = 0;
}
else if(a == "true" && f)
{
s.push(false);
f = false;
x++;
y = 0;
}
else if(a == "false" && f)
{
s.push(true);
f = false;
x++;
y = 0;
}
if(A && (a == "false" || a == "true"))d = true;
if(A && d)
{
b = s.top();
s.pop();
if(s.empty())printf("error");
c = s.top();
s.pop();
s.push(b & c);
A = false;
d = false;
}
if(x > 1 || y > 1)
{
printf("error");
return 0;
}
}
if(x > 1 || f || s.empty())
{
printf("error");
return 0;
}
while(s.size() > 1)
{
b = s.top();
s.pop();
c = s.top();
s.pop();
s.push(b | c);
}
if(s.top())
{
printf("true");
return 0;
}
printf("false");
return 0;
}