博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(递归)2106:Boolean Expressions
阅读量:4560 次
发布时间:2019-06-08

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

描述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 file. 
输入The expressions are of a variable length, although will never exceed 100 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. 
输出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. 
样例输入

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

样例输出

Expression 1: FExpression 2: VExpression 3: V

 

我の思考

用递归的思维来实现这个题目,首先要去除包含的空格,把各项拆成子表达式,是否以!开头的算一个,还有表达式(即一个整体的)~还有就是单项,比如V和F。

 

我の代码

#include 
#include
using namespace std; string a=""; bool result; int len=0; int j=0; bool term(); bool expression(); bool sub(); bool term(){ bool result1; if(a[j]=='!'){ j++; result1 = !sub(); }else{ result1 = sub(); } return result1; } bool expression(){ bool result1 = term(); while(j

我の小结

还是觉得自己很愚笨QAQ,这个例子中因为三个函数之间要相互利用,所以得在前面先声明定义。啊,不管怎么样,一定要坚持下去,坚持一定会有结果。

转载于:https://www.cnblogs.com/rimochiko/p/7486941.html

你可能感兴趣的文章
(转)使用 python Matplotlib 库绘图
查看>>
进程/线程切换原则
查看>>
正则表达式语法
查看>>
20165301 2017-2018-2 《Java程序设计》第四周学习总结
查看>>
Vue的简单入门
查看>>
urllib 中的异常处理
查看>>
通过SQL Server的扩展事件来跟踪SQL语句在运行时,时间都消耗到哪儿了?
查看>>
比较:I/O成员函数getline() 与 get()(第二种用法)的用法异同
查看>>
WIFI密码破解全攻略
查看>>
gulp
查看>>
pgsql查询优化之模糊查询
查看>>
不变模式
查看>>
matlab去云雾
查看>>
500lines项目简介
查看>>
Asp.net core logging 日志
查看>>
BOM浏览器对象模型
查看>>
Jq 遍历each()方法
查看>>
Android源码分析:Telephony部分–phone进程
查看>>
关于 redis.properties配置文件及rule
查看>>
WebService
查看>>