题目链接:http://poj.org/problem?id=3295

题意:判断是否是永真式,其中 p q r s t 表示逻辑变量其值为0或者1;

枚举所有逻辑变量的值,然后判断是否出现false

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<stack> using namespace std; #define met(a, b) memset(a, b, sizeof(a))
#define N 111 typedef long long LL; int p, q, r, s, t, len;
char str[N]; bool Judge()
{
stack<int> Sta;
for(int i=len-; i>=; i--)
{
int x1, x2;
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')
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push(x1&&x2);
}
else if(str[i] == 'A')
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push(x1||x2);
}
else if(str[i] == 'N')
{
x1 = Sta.top();Sta.pop();
Sta.push(!x1);
}
else if(str[i] == 'C')
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push( !(x1&&!x2) );
}
else
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push( x1==x2 );
}
}
return Sta.top()==;
} bool solve()
{
len = strlen(str); for(p=; p<; p++)
for(q=; q<; q++)
for(r=; r<; r++)
for(s=; s<; s++)
for(t=; t<; t++)
if(!Judge())
return false;
return true;
} int main()
{
while(scanf("%s", str), strcmp(str, ""))
{
if(solve())puts("tautology");
else puts("not");
}
return ;
}

最新文章

  1. MySQL5.6 PERFORMANCE_SCHEMA 说明
  2. 图像预处理第9步:存为.bmp文件
  3. spider_text
  4. Java Servlet(八):EL自定义函数
  5. jQueryMobile控件之页面切换
  6. Java list的用法排序及遍历
  7. Windows 多线程知识点汇总
  8. JDBC中的批量插入和乱码解决
  9. 终极解决方案:windows10开机黑屏,死机
  10. NOI2003 文本编辑器
  11. Swift 2.0 字符串学习笔记(建议掌握OC字符串知识的翻阅)
  12. .NetCore之下载文件
  13. Android面试题总结
  14. .NET Core微服务之基于MassTransit实现数据最终一致性(Part 2)
  15. shiro(四)项目开发中的配置、
  16. Redmine简易安装与系统优化
  17. Android获取虚拟软键盘高度
  18. Pychram 在model中修改class属性值后更新到Navicat Premium中
  19. Python-垃圾回收机制
  20. 关于servelet入门介绍

热门文章

  1. vux ajax请求 及 跨域
  2. 使用 requests 维持会话
  3. C#调用DLL报“试图加载格式不正确的程序”
  4. erlang安装
  5. iOS - UITableViewStylePlain与UITableViewStyleGroup样式的对比
  6. free -m 下的含义
  7. 【.NetCore学习】ASP.NET Core EF Core2.0 DB First现有数据库自动生成实体Context
  8. android checkbox样式
  9. 深入理解 Neutron -- OpenStack 网络实现(1):GRE 模式
  10. 【SpringCloud微服务实战学习系列】配置详解