博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Boolean Expressions
阅读量:4364 次
发布时间:2019-06-07

本文共 2576 字,大约阅读时间需要 8 分钟。

Description

The objective of the program you are going to produce is to evaluate boolean expressions as the one shown next:
Expression: ( V | V ) & F & ( F | V )
where V is for True, and F is for False. The expressions may include the following operators: ! for not, & for and, | for or, the use of parenthesis for operations grouping is also allowed. To perform the evaluation of an expression, it will be considered the priority of the operators, the not having the highest, and the or the lowest. The program must yield V or F, as the result for each expression in the input.

Input

The expressions are of a variable length, although will never exceed 2000 symbols. Symbols may be separated by any number of spaces or no spaces at all, therefore, the total length of an expression, as a number of characters, is unknown.
The number of expressions in the input file is variable and will never be greater than 20. Each expression is presented in a new line, as shown below.

Output

For each test expression, print “Expression “ followed by its sequence number, “: ”, and the resulting value of the corresponding test expression. Separate the output for consecutive test expressions with a new line.
Use the same format as that shown in the sample output shown below.

Sample Input

( V | V ) & F & ( F| V)
!V | V & V & !F & (F | V ) & (!F | F | !V & V)
(F&F|V|!V&!F&!(F|F&V))

Sample Output

Expression 1: F
Expression 2: V
Expression 3: V

Source

 

1 #include 
2 #include
3 //#include
4 //using namespace std; 5 char str[2005]; 6 typedef struct stack{ 7 char buf[2000]; 8 int p; 9 stack(){ 10 p=-1; 11 } 12 void push(char a){ 13 buf[++p]=a; 14 } 15 void pop(){ 16 p--; 17 } 18 bool empty(){ 19 if(p==-1) return true; 20 else return false; 21 } 22 char top(){ 23 char tmp=buf[p]; 24 return tmp; 25 } 26 27 }stack; 28 stack op; 29 stack in; 30 char isNOT(char tmp){
//push进一个数字之前看看op.top是不是! 31 while(op.top()=='!'){ 32 op.pop(); 33 tmp=(tmp=='V'?'F':'V'); 34 } 35 return tmp; 36 } 37 //stack
op;//操作符 38 //stack
in;//操作数 39 int main(){ 40 int count=0; 41 while(gets(str)){ 42 int i; 43 while(!op.empty()) op.pop(); 44 while(!in.empty()) in.pop(); 45 for(i=0;i

 

转载于:https://www.cnblogs.com/yexinyu/p/6516856.html

你可能感兴趣的文章
程序媛,坚持这几个好习惯让你越来越美
查看>>
如何在本地运行查看github上的开源项目
查看>>
类成员函数模板特化
查看>>
十个利用矩阵乘法解决的经典题目
查看>>
sublime text3
查看>>
WPF 反编译后错误处理
查看>>
varnish基础
查看>>
3.3-3.9 周记
查看>>
博客换肤
查看>>
HDU 5025Saving Tang Monk BFS + 二进制枚举状态
查看>>
Web Magic 总体架构
查看>>
Scikit-Learn机器学习入门
查看>>
完美解决IE8有两个进程的问题
查看>>
jq的链式调用.end();
查看>>
不要怂,就是GAN (生成式对抗网络) (五):无约束条件的 GAN 代码与网络的 Graph...
查看>>
单击浏览器右上角的X弹出提示窗口
查看>>
BZOJ1734: [Usaco2005 Feb]Aggressive cows 愤怒的牛
查看>>
开始python之旅
查看>>
Python进阶06 循环对象
查看>>
Python补充06 Python之道
查看>>