poj 2106 Boolean Expressions 课本代码
#include<cstdio>
const int maxn=100 +10; int val[maxn],vtop;
int op[maxn],otop; void insert(int b)
{
while(otop &&op[otop-1]==3)
{
b=!b;
--otop;
}
val[vtop++]=b;
} void calc(void)
{
int b=val[--vtop];
int a=val[--vtop];
int opr=op[--otop]; int c=(a&b);
if(opr==1)
c=(a|b);
insert(c);
} int main(void)
{
int loop=0; char c;
while((c=getchar())!=EOF)
{
vtop=otop=0; do
{
if(c=='(')
{
op[otop++]=0;
}
else if(c==')')
{
while(otop&&op[otop-1]!=0)
calc();
--otop;
insert(val[--vtop]);// 当表达式是!()时,这一句是计算完 () 后,计算 前面的 ! 的
}
else if(c=='!')
{
op[otop++]=3;
}
else if(c=='&')
{
while(otop&&op[otop-1]>=2)
calc();
op[otop++]=2;
}
else if(c=='|')
{
while(otop&&op[otop-1]>=1)
calc();
op[otop++]=1;
}
else if(c=='V'||c=='F')
{
insert(c=='V'?1:0);
}
}
while((c=getchar())!='\n'&&c!=EOF);
while(otop)
calc(); printf("Expression %d: %c\n",++loop,(val[0]?'V':'F'));
}
return 0; }
poj 2106 Boolean Expressions 课本代码的更多相关文章
- [poj 2106] Boolean Expressions 递归
Description The objective of the program you are going to produce is to evaluate boolean expressions ...
- POJ 2106 Boolean Expressions
总时间限制: 1000ms 内存限制: 65536kB 描述 The objective of the program you are going to produce is to evaluate ...
- POJ 2106 Boolean Expressions (布尔表达式求值)
题意:关于!,&,| 的运算,表达式中V代表true,F代表false. 思路:见代码吧,很详细了. 要注意 !!!F,!(...) 的情况. #include <iostream> ...
- (栈的应用5.2.2)POJ 2106 Boolean Expressions(表达式求值)
/* * POJ_2106.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...
- Boolean Expressions POJ - 2106 (表达式求值)
The objective of the program you are going to produce is to evaluate boolean expressions as the one ...
- POJ | Boolean Expressions
总时间限制: 1000ms 内存限制: 65536kB 描述The objective of the program you are going to produce is to evaluate ...
- Boolean Expressions
Boolean Expressions Time Limit: 1000MS Memory Limit: 30000K Description The objective of the ...
- shorthand trick with boolean expressions
https://stackoverflow.com/questions/2802055/what-does-the-construct-x-x-y-mean --------------------- ...
- 组合数学poj 1496 1850 同样的代码过两题
Description 1942 Transmitting and memorizing information is a task that requires different coding ...
随机推荐
- 《TomCat与Java Web开发技术详解》(第二版) 第四章节的学习总结--常用Servlet API
要开发Servlet,自然要掌握常用的servlet的相关API.通过此章节的学习,了解到如下常用API 1.Servlet接口--->GenericServlet抽象类(实现Servlet接口 ...
- HDU3351 Seinfeld 【贪心】
Seinfeld Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- ubuntu openfire Server install
1.首先登录到ubuntu server.在安装openfire 服务器之前,先确保你的系统已经更新到最新.然后输入下面的命令,一行一行执行,最后安装可用的更新 sudo apt-get update ...
- python 常用数据结构
#coding=utf- #元组,不可变序列(,) a=(,,,) print(a) a=tuple([,,,])#第二种定义方式 print(a) print(a[]) print(a[:]) #可 ...
- 关于angularjs的model的一些问题
有的时候 在一些页面中 我们会需要用到弹出的模态框,这里主要是使用angularjs的uimodel. 页面效果如下: 首先我们需要在JS的controller中导入$uibModal模块. HTML ...
- 快捷标签和ajax、json返回数据
<if 判断条件>标签</if><import>标签可以链接外部的样式表,和js<import file="js.util.Array" ...
- 2820: YY的GCD
2820: YY的GCD Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1693 Solved: 901[Submit][Status][Discu ...
- python 深复制与浅复制------copy模块
模块解读: 浅复制: x = copy.copy(y)深复制: x = copy.deepcopy(y)(注:模块特有的异常,copy.Error) 深copy与浅copy的差别主要体现在当有混合对象 ...
- 九度OJ 1351:数组中只出现一次的数字 (位运算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3098 解决:906 题目描述: 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 输入: 每个 ...
- Pipeline模式(netty源码死磕6)
精进篇:netty源码死磕6 巧夺天工--Pipeline模式揭秘 1. 巧夺天工--Pipeline模式揭秘 1.1. Pipeline模式简介 管道的发名者叫,Malcolm Douglas M ...