对p,q,r,s,t进行循环,若32种情况均可,则正确,否则不行
其实类似于前缀表达式,只不过是布尔型的而已
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #include<queue> #include<math.h> #include<stack> using namespace std; #define LL long long #define mp(a,b) make_pair((a),(b)) #define clr(x,a) memset(x,a,sizeof(x)) #define INF 0x3f3f3f3f #define lb(x) ((x)&(-x)) #define rep(i,a,b) for(int i=a;i<=b;i++) const int N=1005,siz=1e9; const int MOD=1e9+7; int d; char str[120]; bool solve(int p,int q,int r,int s,int t){ stack<bool> sta; int len=strlen(str); for(int i=len-1;i>=0;i--){ if(str[i]=='p') sta.push(p); if(str[i]=='q') sta.push(q); if(str[i]=='r') sta.push(r); if(str[i]=='s') sta.push(s); if(str[i]=='t') sta.push(t); if(str[i]=='N'){ bool tmp=sta.top(); sta.pop(); sta.push(!tmp); } if(str[i]=='K'){ bool tmp2=sta.top(); sta.pop(); bool tmp1=sta.top(); sta.pop(); sta.push(tmp1 & tmp2); } if(str[i]=='A'){ bool tmp2=sta.top(); sta.pop(); bool tmp1=sta.top(); sta.pop(); sta.push(tmp1 | tmp2); } if(str[i]=='E'){ bool tmp2=sta.top(); sta.pop(); bool tmp1=sta.top(); sta.pop(); sta.push(tmp1==tmp2); } if(str[i]=='C'){ bool tmp2=sta.top(); sta.pop(); bool tmp1=sta.top(); sta.pop(); if(tmp1==true && tmp2==false) sta.push(false); else sta.push(true); } } return sta.top(); } int main() { //freopen("aaa.txt","r",stdin); //freopen("bbb.txt","w",stdout); int T; while(~scanf("%s",str)){ if(!strcmp(str,"0")) break; bool ok=1; rep(p,0,1) rep(q,0,1) rep(r,0,1) rep(s,0,1) rep(t,0,1){ ok &=solve(p,q,r,s,t); } puts(ok?"tautology":"not"); } return 0; }