WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of the possible symbols K, A, N, C, E, p, q, r, s, t. A Well-formed formula (WFF) is any string of these symbols obeying the following rules:

  • p, q, r, s, and t are WFFs
  • if w is a WFF, Nw is a WFF
  • if w and x are WFFs, Kwx, Awx, Cwx, and Ewx are WFFs.

The meaning of a WFF is defined as follows:

  • p, q, r, s, and t are logical variables that may take on the value 0 (false) or 1 (true).
  • K, A, N, C, E mean and, or, not, implies, and equals as defined in the truth table below.
Definitions of K, A, N, C, and E
     w  x   Kwx   Awx    Nw   Cwx   Ewx
  1  1   1   1    0   1   1
  1  0   0   1    0   0   0
  0  1   0   1    1   1   0
  0  0   0   0    1   1   1

A tautology is a WFF that has value 1 (true) regardless of the values of its variables. For example, ApNp is a tautology because it is true regardless of the value of p. On the other hand, ApNq is not, because it has the value 0 for p=0, q=1.

You must determine whether or not a WFF is a tautology.

Input

Input consists of several test cases. Each test case is a single line containing a WFF with no more than 100 symbols. A line containing 0 follows the last case.

Output

For each test case, output a line containing tautology or not as appropriate.

Sample Input

ApNp
ApNq
0

Sample Output

tautology
not 就是离散数学的一个模拟,判断所给的式子是不是永真公式
用栈逆序推还不算难
 #include<stdio.h>
#include<iostream>
#include<string.h>
#include<stack>
using namespace std;
stack<int>sta;
int p,q,r,s,t,a,b;
char str[];
int f()
{
int len=strlen(str);
for(int i=len-; i>-; i--)
{
if(str[i]=='p')sta.push(p);//是字符直接入栈
else if(str[i]=='q')sta.push(q);
else if(str[i]=='r')sta.push(r);
else if(str[i]=='s')sta.push(s);
else if(str[i]=='t')sta.push(t);
else if(str[i]=='K')//是运算就进行运算
{
a=sta.top();
sta.pop();
b=sta.top();
sta.pop();
sta.push(a&&b);
}
else if(str[i]=='A')
{
a=sta.top();
sta.pop();
b=sta.top();
sta.pop();
sta.push(a||b);
}
else if(str[i]=='C')
{
a=sta.top();
sta.pop();
b=sta.top();
sta.pop();
if(a&&!b)sta.push();
else sta.push();
}
else if(str[i]=='E')
{
a=sta.top();
sta.pop();
b=sta.top();
sta.pop();
if(a==b)sta.push();
else sta.push();
}
else if(str[i]=='N')
{
a=sta.top();
sta.pop();
sta.push(!a);
}
}
return sta.top();
}
int sf()//枚举各种情况
{
for(p=; p<; p++)
for(q=; q<; q++)
for(r=; r<; r++)
for(s=; s<; s++)
for(t=; t<; t++)
if(!f())
return ;
return ;
}
int main()
{
while(gets(str))
{
if(!strcmp(str,""))
break;
else
{
if(sf())
printf("tautology\n");
else
printf("not\n");
}
}
return ;
}

Tautology的更多相关文章

  1. [POJ3295]Tautology

    [POJ3295]Tautology 试题描述 WFF 'N PROOF is a logic game played with dice. Each die has six faces repres ...

  2. Tautology(structure)

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10061   Accepted: 3826 Descri ...

  3. Tautology 分类: POJ 2015-06-28 18:40 10人阅读 评论(0) 收藏

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10428   Accepted: 3959 Descri ...

  4. poj 3295 Tautology

    点击打开链接 Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8127   Accepted: 3115 ...

  5. POJ3295——Tautology

    Tautology Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...

  6. poj 3295 Tautology (构造)

    题目:http://poj.org/problem?id=3295 题意:p,q,r,s,t,是五个二进制数. K,A,N,C,E,是五个运算符. K:&& A:||N:! C:(!w ...

  7. POJ 3295 Tautology (构造题)

    字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑 ...

  8. POJ3295 Tautology(枚举)

    题目链接. 分析: 最多有五个变量,所以枚举所有的真假值,从后向前借助于栈验证是否为永真式. #include <iostream> #include <cstring> #i ...

  9. poj 3295 Tautology(栈)

    题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...

随机推荐

  1. [置顶] Java Web开发教程来袭

    Java Web,是用Java技术来解决相关web互联网领域的技术总和.web包括:web服务器和web客户端两部分.Java在客户端的应用有java applet不过现在使用的很少,Java在服务器 ...

  2. GCC相关的环境变量

    介绍GCC在编译阶段和程序运行阶段用到的环境变量. GCC编译时用到的环境变量 GCC编译时用到的变量. C_INCLUDE_PATH GCC编译时查找头文件的目录列表.比如: echo $C_INC ...

  3. ArrayBlockingQueue 源码阅读 问题(一)

    今天阅读java.util.concurrent 中 ArrayBlockingQueue 的源码,发现其中有很多下面这行代码 final ReentrantLock lock = this.lock ...

  4. 移动前端之 zepto

    移动前端之 zepto http://qtown.corp.qunar.com/media/video/detail?id=1084&type=1&title=%E5%86%AF%E5 ...

  5. oracle周数计算方法

    从星期天开始起算 Function Fn_GetWeekbyDate(P_Date Varchar2) Return Varchar2 Is Begin Return To_char(To_Date( ...

  6. JS快速排序和去重

    JS的快速排序和JS去重在面试的时候问的挺多的.下面是我对快速排序的理解,和快速排序,去重的代码. 1.什么是快速排序? 第一步: 快速排序就是去个中间值,把比中间值小的放在左边设为arrLeft,比 ...

  7. 2016年11月1日——jQuery源码学习笔记

    1.instanceof运算符希望左操作数是一个对象,右操作数标识对象的类.如果左侧的对象是右侧类的实例,则表达式返回true,否则返回false 2.RegExp.exec() 如果 exec() ...

  8. Android图表引擎AChartEngine之折线图使用

    最近在帮老师做一个课题,其中app端需要显示折线图以便直观地看数据波动,上网查了些资料后发现了这款图标引擎,另外感谢李坤老师的博客,帮助很大. 废话不多说,下面写代码. 一.AChartEngine是 ...

  9. 多线程lock(instance)中instance的选择.

    如我的提问:http://bbs.csdn.net/topics/390496351?page=1#post-394837834 拥有类原子功能的类: class ShareState { //原子功 ...

  10. google的西联汇款可以使用工行代收