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

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

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 <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
using namespace std; const int Max=1100000; int Arr[6];
int top;
string str;
stack<int>a;
void Bit(int num)
{
int top=0;
memset(Arr,0,sizeof(Arr));
while(num)
{
Arr[top++]=num%2;
num/=2;
}
}
bool Jud(char s)
{
switch(s)
{
case 'p':a.push(Arr[0]);break;
case 'q':a.push(Arr[1]);break;
case 'r':a.push(Arr[2]);break;
case 's':a.push(Arr[3]);break;
case 't':a.push(Arr[4]);break;
default :return 0;
}
return 1;
}
void Count(char s)
{
switch(s)
{
case 'K':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push(x&&y);
}
break;
case 'A':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push(x||y);
}
break;
case 'N':
{
int x=a.top();a.pop();
a.push(!x);
}
break;
case 'C':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push((!x)||y);
}
break;
case 'E':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push(x==y);
}
break;
}
}
bool Cal()
{
int len=str.length();
for(int i=0;i<=31;i++)
{
Bit(i);
for(int j=len-1;j>=0;j--)
{
if(!Jud(str[j]))
{
Count(str[j]);
}
}
int x=a.top();
a.pop();
if(!x)
return false;
}
return true;
}
int main()
{
while(cin>>str)
{
if(str=="0")
break;
if(Cal())
{
cout<<"tautology"<<endl;
}
else
{
cout<<"not"<<endl;
}
} }

版权声明:本文为博主原创文章,未经博主允许不得转载。

Tautology 分类: POJ 2015-06-28 18:40 10人阅读 评论(0) 收藏的更多相关文章

  1. 灰度世界算法(Gray World Algorithm) 分类: 图像处理 Matlab 2014-12-07 18:40 874人阅读 评论(0) 收藏

    人的视觉系统具有颜色恒常性,能从变化的光照环境和成像条件下获取物体表面颜色的不变特性,但成像设备不具有这样的调节功能, 不同的光照环境会导致采集的图像颜色与真实颜色存在一定程度的偏差,需要选择合适的颜 ...

  2. Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏

    全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...

  3. Emag eht htiw Em Pleh 分类: POJ 2015-06-29 18:54 10人阅读 评论(0) 收藏

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2937   Accepted: ...

  4. 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏

    Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

  5. Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏

    #include <cstdio> #include <cstdlib> #include <climits> #include <cstring> # ...

  6. Ubuntu vim+ ctags(包含系统函数) + taglist 配置 分类: vim ubuntu 2015-06-09 18:19 195人阅读 评论(0) 收藏

    阅读大型代码,我们经常需要打开很多的代码文件,搜索各种定义.windows下用惯了ide的朋友,转战Linux的时候可能会觉得很难受,找不到合适的阅读工具.其实万能的vim就可以实现.下面介绍一下vi ...

  7. mount命令以及mount ntfs硬盘权限权限与显示的问题 分类: shell ubuntu 2014-11-08 18:29 148人阅读 评论(0) 收藏

    sudo mount -t 文件系统类型 -o 可设置选项 设备路经 访问路经 #常用文件类型如下: iso9660 光驱文件系统, vfat fat/fat32分区, ntfs ntfs分区, sm ...

  8. 由 argv引出的main参数 分类: C/C++ 2014-11-08 18:00 154人阅读 评论(0) 收藏

    我们经常用的main函数都是不带参数的.因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这 ...

  9. [leetcode] Reverse Linked List 分类: leetcode 算法 2015-07-09 18:44 2人阅读 评论(0) 收藏

    反转链表:比较简单的问题,可以遍历也可以递归. # Definition for singly-linked list. class ListNode: def __init__(self, x): ...

随机推荐

  1. Lintcode: Segment Tree Build

    The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...

  2. Eclipse Ctrl+Tab Alt+/ 快捷键

    原来Eclipse的Next Editor 快捷键是 Ctrl+Tab 但是后几个版本将这个快捷键改为Ctrl+F6 了 在Keys设置下面 搜索 NextEditor 将其设置回来即可 同样 原来C ...

  3. PHP Parse Error: syntax error, unexpected $end 错误的解决办

    可以在php.ini中设置short_open_tag = On 第一步,登录到sql命令行   第二步,使用sql语句修改root密码 使用sql语句改密码时一定要选中数据库 .使用 use mys ...

  4. PHP——字符串处理部分

    PHP——字符串处理 下面我们来讲一下我们经常使用的一些字符串处理的函数 1.string(变量);——取这个变量里面的字符串的长度 2.var_dump(变量a,变量b);——判断两个变量里面的字符 ...

  5. CCF真题之图像旋转

    201503-1 问题描述 旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度. 计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可. 输入格式 ...

  6. spark小技巧-mapPartitions

    与map方法类似,map是对rdd中的每一个元素进行操作,而mapPartitions(foreachPartition)则是对rdd中的每个分区的迭代器进行操作.如果在map过程中需要频繁创建额外的 ...

  7. mongodb子文档查询

    --子文档分页 -- 测试数据 db.childTests.insert({ "_id" : 1, "item" : "ABC", &quo ...

  8. 夺命雷公狗---DEDECMS----21dedecms按照地区取出电影内容

    我们现在要做的就是: 这些电影都是要按照地区来取出才可以的,但是我们arclist标签里面有没有按照条件来查找的地方,我们只好换套路了,要不然条条大路都不通,,,, 我们先来构造一条语句: 他这个标签 ...

  9. 手机端js事件支持(event)

    http://blog.163.com/rex_blog/blog/static/1944801012013102743014369/ 所有被测试的浏览器都支持touchstart.touchend和 ...

  10. [php] PHPStorm8 for Yincart project

    PHPStorm8 license for Yincart project: https://github.com/yinheark/yincart2 User Name: Yincart ===== ...