Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10437   Accepted: 3963

Description

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

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

p,q,r,s,t,是五个二进制数。

K,A,N,C,E,是五个运算符。

K:&&

A:||
N:!

C:(!w)||x

E:w==x

这道题可以将p,q,r,s,t穷举

 #include <iostream>
#include<string.h>
#include <stack>
using namespace std;
int p, q, r, s, t;
int len;
char str[];
int result() {
stack<int> res;
int t1,t2;
for (int i = len - ; i >= ; i--) {
switch (str[i]) {
case 'p':
res.push(p);
break;
case 'q':
res.push(q);
break;
case 'r':
res.push(r);
break;
case 's':
res.push(s);
break;
case 't':
res.push(t);
break;
case 'K':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 & t2) {
res.push();
} else {
res.push();
}
break;
case 'A':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 | t2)
res.push();
else
res.push();
break;
case 'N':
t1 = res.top();
res.pop();
if (~t1 & )
res.push();
else
res.push();
break;
case 'C':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if ((~t1 & ) | t2) {
res.push();
} else {
res.push();
}
break;
case 'E':
t1 = res.top();
res.pop();
t2 = res.top();
res.pop();
if (t1 == t2) {
res.push();
} else {
res.push();
}
break;
}
}
return res.top();
} int fun() {
int flag;
for (p = ; p < ; p++) {
for (q = ; q < ; q++) {
for (r = ; r < ; r++) {
for (s = ; s < ; s++) {
for (t = ; t < ; t++) {
flag = result();
if(flag==)
return ;
}
}
}
}
}
return ;
} int main() {
while (cin >> str) {
if (strcmp(str, "") == )
break;
len = strlen(str);
int flag=fun();
if(flag)
cout<<"tautology"<<endl;
else
cout<<"not"<<endl;
}
}

Tautology - poj 3295的更多相关文章

  1. poj 3295 Tautology (构造)

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

  2. poj 3295 Tautology(栈)

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

  3. POJ 3295 Tautology(构造法)

    http://poj.org/problem?id=3295 题意: 判断表达式是否为永真式. 思路: 把每种情况都枚举一下. #include<iostream> #include< ...

  4. poj 3295 Tautology 伪递归

    题目链接: http://poj.org/problem?id=3295 题目描述: 给一个字符串,字符串所表示的表达式中p, q, r, s, t表示变量,取值可以为1或0.K, A, N, C, ...

  5. POJ 3295 Tautology(构造法)

    题目网址:http://poj.org/problem?id=3295 题目: Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  6. 构造 + 离散数学、重言式 - POJ 3295 Tautology

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

  7. POJ 3295 Tautology (构造题)

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

  8. poj 3295 Tautology

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

  9. POJ 3295 Tautology 构造 难度:1

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9580   Accepted: 3640 Descrip ...

随机推荐

  1. Count and Say (Array Length Encoding) -- LeetCode

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  2. Parse error: syntax error, unexpected end of file in *.php on line * 解决方法

    Parse error: syntax error, unexpected end of file in *.php on line * 解决方法   这篇文章主要介绍了PHP错误Parse erro ...

  3. Android 版 Facebook 登录

    Android 版 Facebook SDK 让用户可以通过 Facebook 登录注册您的应用.通过 Facebook 登录您的应用时,用户可以向应用授予权限,以便您可以检索信息或以用户的身份在 F ...

  4. 【微信】微信小程序 获取本次场景值

    场景值: 代表从何处进入小程序的.代表小程序的入口场景值. 注意: 1>目前仅可以在 App 的 onlaunch 和 onshow 中获取上述场景值 获取场景值的方法: //在小程序的onLa ...

  5. mapx 32位在win8 64位上使用

    在可以安装32位mapx的电脑上安装并破解后,将安装文件复制出来,放到c盘根目录下,用下面语句进行注册即可 Regsvr32 C:\MapX\Mapx50.DLL Regsvr32 C:\\MapX\ ...

  6. JAVA Eclipse如何设置编程环境字体

    窗口-首选项-常规-外观-颜色和字体,文本字体  

  7. kali渗透综合靶机(一)--Lazysysadmin靶机

    kali渗透综合靶机(一)--Lazysysadmin靶机 Lazysysadmin靶机百度云下载链接:https://pan.baidu.com/s/1pTg38wf3oWQlKNUaT-s7qQ提 ...

  8. DeleteDC、ReleaseDC 、DeleteObject的使用

    DeleteDC 该函数删除指定的设备上下文环境(DC). 原型: BOOL DeleteDC(HDC hdc): 参数: hdc:设备上下文环境的句柄. 返回值: 成功,返回非零值:失败,返回零.调 ...

  9. ecplise内存配置

    -server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m -XX:+UseG1GC

  10. 【LoadRunner】安装LoadRunner

    LoadRunner安装 下载好LoadRunner安装包,点击运行 在点击安装后,会提示需要安装一下程序,直接点击[确定]安装即可. 上述程序安装完毕后,会自动弹出下面的窗口,点击[下一步] 选择[ ...