poj3295 布尔型的前缀表达式

对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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值