Tautology 分类: POJ 2015-06-28 18:40 10人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- 灰度世界算法(Gray World Algorithm) 分类: 图像处理 Matlab 2014-12-07 18:40 874人阅读 评论(0) 收藏
人的视觉系统具有颜色恒常性,能从变化的光照环境和成像条件下获取物体表面颜色的不变特性,但成像设备不具有这样的调节功能, 不同的光照环境会导致采集的图像颜色与真实颜色存在一定程度的偏差,需要选择合适的颜 ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
- 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: ...
- 周赛-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 ...
- Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏
#include <cstdio> #include <cstdlib> #include <climits> #include <cstring> # ...
- Ubuntu vim+ ctags(包含系统函数) + taglist 配置 分类: vim ubuntu 2015-06-09 18:19 195人阅读 评论(0) 收藏
阅读大型代码,我们经常需要打开很多的代码文件,搜索各种定义.windows下用惯了ide的朋友,转战Linux的时候可能会觉得很难受,找不到合适的阅读工具.其实万能的vim就可以实现.下面介绍一下vi ...
- mount命令以及mount ntfs硬盘权限权限与显示的问题 分类: shell ubuntu 2014-11-08 18:29 148人阅读 评论(0) 收藏
sudo mount -t 文件系统类型 -o 可设置选项 设备路经 访问路经 #常用文件类型如下: iso9660 光驱文件系统, vfat fat/fat32分区, ntfs ntfs分区, sm ...
- 由 argv引出的main参数 分类: C/C++ 2014-11-08 18:00 154人阅读 评论(0) 收藏
我们经常用的main函数都是不带参数的.因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这 ...
- [leetcode] Reverse Linked List 分类: leetcode 算法 2015-07-09 18:44 2人阅读 评论(0) 收藏
反转链表:比较简单的问题,可以遍历也可以递归. # Definition for singly-linked list. class ListNode: def __init__(self, x): ...
随机推荐
- java io读书笔记(5) Writing Bytes to Output Streams
outputstream类是所有的字符输出类的父类,他是一个抽象类. 对于OutputStream类来说,其最基础的方法就是:write(). public abstract void write(i ...
- C++Primer 第三章
//1.位于头文件中的代码一般不应该使用using声明.这是因为头文件的内容会拷贝到所有引用它的文件中,可能会产生始料未及的命名空间冲突. // 三种使用命名空间中的名字的方法 using names ...
- html 鼠标移入标签 显示小手指
<div style="width: 200px; height: 200px; background: red; cursor: pointer;"></div ...
- 纪念我sgu第一个10题!
哎,等下次再做20题纪念一下!尼玛,根本做不出来,还要到处翻别人的555555555555
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- 在Tomcat里使用配置连接池连接数据库
一:首先在Tomcat下的conf/context.xml文件里的contenx标签里配置数据源: <Resource name="jdbc/zzz" auth=" ...
- 【fedora】设置中文为默认语言
安装Fedora时,界面语言是英语,手动安装简体中文语言包: 1.打开终端,执行yum install system-config-language命令来安装语言套件: 2.然后执行system-co ...
- C语言初学者代码中的常见错误与瑕疵(19)
见:C语言初学者代码中的常见错误与瑕疵(19)
- 形状特征提取-Hu不变矩(转载)
[原文部分转载]:http://blog.csdn.net/wrj19860202/archive/2011/04/16/6327094.aspx 在连续情况下,图像函数为 ,那么图像的p+q阶几何矩 ...
- struts2 笔记02 文件上传、文件下载、类型转换器、国际化的支持
Struts2的上传 1. Struts2默认采用了apache commons-fileupload 2. Struts2支持三种类型的上传组件 3. 需要引入commons-fileupload ...