POJ3295

16 篇文章 0 订阅

看到的时候完全没有想到位操作。。。还是差好多


#include <iostream>

#include <stdio.h>
#include <string.h>
#include <stack>


using namespace std;


int main()
{
    int p[] = {1,0};
    int q[] = {1,0};
    int r[] = {1,0};
    int s[] = {1,0};
    int t[] = {1,0};




    char str[110];
    stack <int> sta;


    while(scanf("%s",str), str[0] != '0')
    {
        bool flag = true;
        int len = strlen(str);


        for( int i1 = 0; i1 <= 1; i1++)
         {
             for( int i2 = 0; i2 <= 1; i2++)
              {
                  for( int i3 = 0; i3 <= 1; i3++)
                   {
                       for( int i4 = 0; i4 <= 1; i4++)
                       {
                           for( int i5 = 0; i5 <= 1; i5++)
                           {
                               for( int i = len - 1; i >= 0; i--)
                               {
                                  if(str[i] >= 'Z')
                                   {
                                      if(str[i] == 'p')
                                        sta.push(q[i1]);
                                      else if(str[i] == 'q')
                                        sta.push(q[i2]);
                                      else if(str[i] == 'r')
                                        sta.push(q[i3]);
                                      else if(str[i] == 's')
                                        sta.push(q[i4]);
                                      else if(str[i] == 't')
                                        sta.push(q[i5]);
                                   }


                                  else  if(str[i] == 'N')
                                   {
                                         int n = sta.top();
                                         sta.pop();
                                         sta.push(!n);
                                   }


                                  else if(str[i] == 'A')
                                   {
                                      int n = sta.top();
                                      sta.pop();
                                      int m = sta.top();
                                      sta.pop();
                                      int temp =( n || m);
                                      sta.push(temp);
                                   }


                                  else if(str[i] == 'K')
                                   {
                                      int n = sta.top();
                                      sta.pop();
                                      int m = sta.top();
                                      sta.pop();
                                      int temp = (n && m);
                                      sta.push(temp);
                                   }


                                  else if(str[i] == 'E')
                                  {
                                      int n = sta.top();
                                      sta.pop();
                                      int m = sta.top();
                                      sta.pop();
                                      int temp = (n == m ? 1 : 0);
                                      sta.push(temp);
                                  }


                                  else if(str[i] == 'C')
                                  {
                                      int n = sta.top();
                                      sta.pop();
                                      int m = sta.top();
                                      sta.pop();
                                      int temp = (!m || n);
                                      sta.push(temp);
                                  }




                               }


                               if(sta.top() == 0)
                               {
                                   flag = false;
                                   goto L;
                               }
                           }
                       }
                   }
              }
         }


     L:
       if(flag)
         cout<<"tautology"<<endl;
      else
         cout<<"not"<<endl;
     }


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值