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 ...
随机推荐
- Jenkins+GitHub+Xcode+fir搭了一个持续集成环境
enkins+GitHub+Xcode+fir搭了一个持续集成环境 字数826 阅读5699 评论44 喜欢49 原文链接 Coding Duck 今天用Jenkins+GitHub+Xcode+fi ...
- eclipse配置jp.gr.java_conf.ussiy.app.propedit_5.3.3
配置PropertiesEditor插件 jp.gr.java_conf.ussiy.app.propedit_5.3.3 1.下载PropertiesEditor插件 http://pan.ba ...
- 搜索maven的库中某个支持库的的最新版本
首先放网址(建议挂个vpn): maven库中心:http://search.maven.org/ jcenter库中心:https://bintray.com/bintray/jcenter 接下来 ...
- UVA 699 The Falling Leaves (二叉树水题)
本文纯属原创.转载请注明出处,谢谢. http://blog.csdn.net/zip_fan. Description Each year, fall in the North Central re ...
- 关于移动端border 1像素在不同分辨率下边显示粗细不一样的处理
最近开发发现一个很有趣的问题 就是我如果给一个元素加上一个像素的 border 在不同的分辨率的情况下显示的不同 在高清屏幕(尤其是ios 喽 不鄙视国产) 据说在6plus下会变成3px 这个我 ...
- Codeforces Round #392 (Div. 2) F. Geometrical Progression
原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...
- poj 2524 Ubiquitous Religions(并查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23168 Accepted: ...
- 九度OJ 1343:城际公路网 (最小生成树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:445 解决:178 题目描述: 为了加快城市之间的通行和物资流动速度,A国政府决定在其境内的N个大中型城市之间,增加修建K条公路.已知这N个 ...
- 九度OJ 1208:10进制 VS 2进制 (进制转换)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2040 解决:612 题目描述: 对于一个十进制数A,将A转换为二进制数,然后按位逆序排列,再转换为十进制数B,我们乘B为A的二进制逆序数. ...
- Frobenius Norm
http://mathworld.wolfram.com/FrobeniusNorm.html