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 ...
随机推荐
- css3 jQuery实现3d搜索框+为空推断
<!DOCTYPE html> <html> <head> <title>css3实现3d搜索框</title> <style> ...
- 为什么使用JSP?
JSP程序与CGI程序有着相似的功能,但和CGI程序相比,JSP程序有如下优势: 性能更加优越,因为JSP可以直接在HTML网页中动态嵌入元素而不需要单独引用CGI文件. 服务器调用的是已经编译好的J ...
- 安装Hadoop 1.1.2 (三 安装配置Hadoop)
1 tar -zxvf hadoop-1.1.2.tar.gz 2 在hadoop/conf目录 (1) 编辑 hadoop-env.sh export JAVA_HOME=/usr/java/jdk ...
- 从零开始写一个Exporter
前言 上一篇文章中已经给大家整体的介绍了开源监控系统Prometheus,其中Exporter作为整个系统的Agent端,通过HTTP接口暴露需要监控的数据.那么如何将用户指标通过Exporter的形 ...
- Linux系统监控的几个命令
uptime 系统时间.运行时间.连接数(没一个终端算一个连接).在1,5,15分钟内系统负载 uname -a 查看系统所有相关信息 -r 查看系统内核版本 -s 查看系统内核名 ...
- Codeforces441C_Valera and Tubes(暴力)
Valera and Tubes time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Yii2数据库操作的各种写法
-------------------------------ActiveRecord---------------------------------------- 查询: // find the ...
- Linux中查找文件和文件内容的常用命令
一.whereis <程序名称> 查找软件的安装路径-b 只查找二进制文件 -m 只查找帮助文件-s 只查找源代码-u 排除指定类型文件-f 只显示文件名-B <目录> 在指定 ...
- 关于用JAVA开发短信方面的知识
现在流行的网络业务莫过于短信了.网易新浪等都因此而盈利,股价上涨.我凭自己的经验和公司支持,也就乘着东风来研究一下了! 首先,你要选择一台移动或者联通的短信服务器做你们的发送短信接口.这是最关键的 ...
- c的详细学习(5)数组
到目前为止,前面介绍的都是属于基本类型的数据.除此之外,C语言还提供了一些更为复杂的数据类型,称为构造类型.数组就是最基本的构造类型.若要针对一批数据进行某种操作,采用数组是一种方便可行的方法 ...