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 ...
随机推荐
- 【Mac系统】之Mysql数据库遇到修改数字密码的问题(SQL语法错误:ERROR 1064 (42000),密码策略等问题:ERROR 1819 (HY000))
安装完Mysql也进行了第一次初始化密码以及修改密码规则(请参考文章),但是我想后续再改密码,出现了下面几个问题: #SQL语句错误问题 ERROR 1064 (42000): You have an ...
- java,jquery对json的解析
json常用于浏览器对服务器的数据传递,所以,我们会经常在浏览器和服务器段对json进行封装和拆装,下面对这些进行简单介绍吧 1,服务器端,也就是java方面,我们用的是 net.sf.json-li ...
- FreeSWITCH版本更新
[1]FreeSWITCH版本更新 从2014年10月底开始,FreeSWITCH代码库改为由stash管理,该管理工具能更好地与jira集成. 如果你以前已经clone了代码,请做如下更新: git ...
- 转载 jenkins执行selenium 测试 浏览器不显示解决方法
原文地址: http://blog.csdn.net/achang21/article/details/45096003 The web browser doesn't show while run ...
- ios输出想保留的整数位(占位符)
int startHour=5; int startMinute=4; //输出前面补0,不管你输入的数据前面有没有0 sp;NSLog(@"====>%@",[NSStri ...
- CF:Problem 426B - Sereja and Mirroring 二分或者分治
这题解法怎么说呢,由于我是把行数逐步除以2暴力得到的答案,所以有点二分的意思,可是昨天琦神说是有点像分治的意思.反正总的来说:就是从大逐步细化找到最优答案. 可是昨晚傻B了.靠! 多写了点东西,然后就 ...
- 为什么是kafka(二)
回答几个网友提出的问题,不清楚的能够看上一篇内容. 1. kafka的删除策略应该怎么配置?为了提升性能.我是不是应该1小时删除一次消费过的数据. 全然能够依据磁盘大小配置.仅仅要磁盘足够用,全然不 ...
- "活在未来" VS “活在当下”(通向财富自由学习笔记六)
之前读过一些灵修类的书籍,<遇见未知的自己>.<当下的力量>等都在告诉我们活在当下很重要,这里笑来老师提出了一个问题,是活在当下重要呢?还是活在未来?,笑来老师给出了很好的答案 ...
- [Sdoi2013]直径(树的直径)
//36分 #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> # ...
- 【BZOJ4028】[HEOI2015]公约数数列 分块
[BZOJ4028][HEOI2015]公约数数列 Description 设计一个数据结构. 给定一个正整数数列 a_0, a_1, ..., a_{n - 1},你需要支持以下两种操作: 1. M ...