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 ...
随机推荐
- ConcurrentHashMap的使用和原理
呵呵呵,原理nmb. HashTable,HashMap,ConcurrentHashMap 当你作为一个菜鸡的时候,别人就会那这个来问你. 为什么要用ConcurrentHashMap,因为Hash ...
- MATLAB循环结构:while语句P69范数待编
while语句的一般格式为: while 条件 循环体语句 end 从键盘输入若干个数,当输入0时结束输入,求这些数的平均值和它们的和. 程序如下: sum=; n=; x=input('输入一个数字 ...
- WCF基础之承载服务和生成客户端
wcf的承载有三种iis.was和自承载,它们如何承载园子里有很多,就不多赘述. 自iis7以后iis支持http和非http的协议,使用iis承载服务与其他两种承载相比,我觉的最明显的是was和自承 ...
- OC中第三方库MJExtension的使用
MJExtension是一套常用的"字典和模型之间互相转换"的框架,在项目中也使用过,现在记录一下.随着Swift的普及,在Swift中也有一个类似功能的框架HandyJSON 也 ...
- Java基础 - 常量与变量
A:常量 内存中的一小块区域,在程序执行过程中,其值不可以发生改变的量称为常量 常量的几种表现形式: a:字符串常量 "HelloWorld" b:整数常量 12 c:小数常量 1 ...
- python基础-第九篇-9.2线程与多线程
单线程 import time beginTime = time.time() for a in range(10): print(a) time.sleep(1) shijian = time.ti ...
- MySql四种隔离级别
什么是事务 事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性,一个事务中的一系列的操作要么全部成功,要么一个都不做. 事务的结束有 ...
- Python读属性文件
# coding:utf-8 class Properties: def __init__(self, file_name): self.file_name = file_name self.prop ...
- Spring AspectJ AOP 完整示例
http://outofmemory.cn/java/spring/AOP/aop-aspectj-example-before-after-AfterReturning-afterThrowing- ...
- Bootstrap学习3--栅格系统
备注:最新Bootstrap手册:http://www.jqhtml.com/bootstraps-syntaxhigh/index.html 目录1.简介2.栅格选项3.列偏移4.嵌套列5.列排序 ...