poj 3295 Tautology
来源:互联网 发布:然足下卜之鬼乎的然 编辑:程序博客网 时间:2024/06/03 21:58
哇呜我好牛逼…竟然一次过…
就是一个逻辑版的波兰计算器
压进来弹出去什么的搞一波…具体不说了…
今年第一次用goto!
(我还记得小时候学编程所有循环都是goto…后来我脑子就坏掉了 什么都用
#include <iostream>#include <stack>std::stack<int> expr;int p, q, r, s, t;char expr_input[105]; bool solve() { int top = 0; int len = strlen(expr_input); for(int i = len - 1;i >= 0;i--) { switch (expr_input[i]) { case 'p': expr.push(p); break; case 'q': expr.push(q); break; case 'r': expr.push(r); break; case 's': expr.push(s); break; case 't': expr.push(t); break; case 'K': { int a = expr.top(); expr.pop(); int b = expr.top(); expr.pop(); expr.push(a&&b); break; } case 'A': { int a = expr.top(); expr.pop(); int b = expr.top(); expr.pop(); expr.push(a||b); break; } case 'N': { int a = expr.top(); expr.pop(); expr.push(!a); break; } case 'C': { int a = expr.top(); expr.pop(); int b = expr.top(); expr.pop(); expr.push((!a)||b); break; } case 'E': { int a = expr.top(); expr.pop(); int b = expr.top(); expr.pop(); expr.push(a==b); break; } } } return expr.top();}int main(int argc, char *argv[]) { while(std::cin >> expr_input && expr_input[0] != '0') { int ok = 1; for(p=0; p<=1; p++) for(q=0; q<=1; q++) for(r=0; r<=1; r++) for(s=0; s<=1; s++) for(t=0; t<=1; t++) { if(!solve()) { ok = 0; goto out_of_siege; } } out_of_siege: if(ok) { std::cout << "tautology" << std::endl; } else { std::cout << "not" << std::endl; } } return 0;}
阅读全文
0 0
- POJ 3295 Tautology 模拟
- POJ-3295-Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology(模拟)
- poj 3295 Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology
- poj 3295 Tautology
- poj-3295 Tautology
- POJ 3295 -Tautology
- POJ 3295 Tautology
- POJ:题号 3295------tautology
- Poj 3295 Tautology
- Tautology POJ 3295
- POJ 3295 Tautology
- poj 3295 Tautology
- linux下RAR和ZIP安装和使用
- centos安装elastix2.4
- 常见端口介绍
- Mysql中文乱码问题完美解决方案
- 老鸟的职场2
- poj 3295 Tautology
- .ascx和.ashx的作用和使用
- ES6语法(1)
- 详解斜率优化
- 关于如何做好自己工作的清单
- Kotlin学习资源
- 百度地图so库文件
- Promise对象的含义和基本用法
- Android硬编码——音频编码、视频编码及音视频混合