poj 3295 Tautology

写一大堆然后一次ac的感觉好爽好爽!!!

第一次用stl害羞害羞害羞

是的,上大学两年来第一次用stl!!!

啊!!!我该鄙视自己还是佩服自己!!!


其实差不多就是四则运算那种,pqrst代表五个值,都是0或1,然后把它们代入表达式,akcge代表运算符,或、与、非balabala

如果不管pqrst的组合怎样最终结果都为1的话就tautlogy,否则就是not


四则运算和表达式运算一般就和栈有关吧,然后stl还是很强大的嘎嘎嘎嘎嘎,在这道题里用起来很方便啊


但是为啥老师给我的任务说这是分治递推题呢……估计我还是不能完全理解分治递推啥意思


感觉自己写的代码比网上的简洁一点,估计是今天男盆友要回来了心情格外好一点哈哈


#include <iostream>
#include <stack>
#include <string.h>
using namespace std;

stack<int> the_stack;

int operator_string(int p,int q,int r,int s,int t,char wff[103])
{
    int len=strlen(wff);
    int i;
    for (i=len-1; i>=0; i--) {
        if (wff[i]=='p')
            the_stack.push(p);
        if (wff[i]=='q')
            the_stack.push(q);
        if (wff[i]=='r')
            the_stack.push(r);
        if (wff[i]=='s')
            the_stack.push(s);
        if (wff[i]=='t')
            the_stack.push(t);
        if (wff[i]=='A') {
            int x=the_stack.top();
            the_stack.pop();
            int y=the_stack.top();
            the_stack.pop();
            the_stack.push(x||y);
        }
        if (wff[i]=='K') {
            int x=the_stack.top();
            the_stack.pop();
            int y=the_stack.top();
            the_stack.pop();
            the_stack.push(x&&y);
        }
        if (wff[i]=='C') {
            int x=the_stack.top();
            the_stack.pop();
            int y=the_stack.top();
            the_stack.pop();
            the_stack.push((!x)||y);
        }
        if (wff[i]=='E') {
            int x=the_stack.top();
            the_stack.pop();
            int y=the_stack.top();
            the_stack.pop();
            the_stack.push(x==y);
        }
        if (wff[i]=='N') {
            int x=the_stack.top();
            the_stack.pop();
            the_stack.push(!x);
        }
    }
    i=the_stack.top();
    the_stack.pop();
    return i;
}

int main(int argc, const char * argv[]) {
    char wff[103];
    while (cin>>wff) {
        if (wff[0]=='0')
            return 0;
        if(operator_string(0, 0, 0, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 0, 0, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 0, 0, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 0, 0, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 0, 1, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 0, 1, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 0, 1, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 0, 1, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 0, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 0, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 0, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 0, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 1, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 1, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 1, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(0, 1, 1, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 0, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 0, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 0, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 0, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 1, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 1, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 1, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 0, 1, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 0, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 0, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 0, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 0, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 1, 0, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 1, 0, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 1, 1, 0,wff)==0)
        {cout<<"not"<<endl;continue;}
        if(operator_string(1, 1, 1, 1, 1,wff)==0)
        {cout<<"not"<<endl;continue;}
        cout<<"tautology"<<endl;
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值