文件名称:EvaluateReversePolishNotation
介绍说明--下载内容均来自于网络,请自行研究使用
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /. Each operand may be an integer or another expression.
Some examples:
[ 2 , 1 , + , 3 , * ] -> ((2 + 1) * 3) -> 9
[ 4 , 13 , 5 , / , + ] -> (4 + (13 / 5)) -> 6
分析:这一题就是写程序计算逆波兰式的结果,遍历表达式,碰到操作数入栈,碰到操作符就从栈顶取出两个操作数,再将计算后的结果入栈,最后栈中剩余的唯一操作数就是计算结果。-. Evaluate the value of an arithmetic expression in Reverse Polish Notation Valid operators are+,-,*,/Each operand may be an integer or another expression Some examples:.. [" 2" , " 1" , " +" , " 3 " ," * " ]-> ((2+ 1)* 3)-> 9 [" 4 " ," 13 " ," 5 " ," /" ," + " ]-> (4+ (13/After this problem is to write a program to calculate the inverse Polish results, iterate expression operand stack encounter, encounter operator to fetch two operands the stack, and then calculated as follows:> 6 Analysis- 5)) The results of the stack, the only remaining operand stack is the final calculations.
Valid operators are +, -, *, /. Each operand may be an integer or another expression.
Some examples:
[ 2 , 1 , + , 3 , * ] -> ((2 + 1) * 3) -> 9
[ 4 , 13 , 5 , / , + ] -> (4 + (13 / 5)) -> 6
分析:这一题就是写程序计算逆波兰式的结果,遍历表达式,碰到操作数入栈,碰到操作符就从栈顶取出两个操作数,再将计算后的结果入栈,最后栈中剩余的唯一操作数就是计算结果。-. Evaluate the value of an arithmetic expression in Reverse Polish Notation Valid operators are+,-,*,/Each operand may be an integer or another expression Some examples:.. [" 2" , " 1" , " +" , " 3 " ," * " ]-> ((2+ 1)* 3)-> 9 [" 4 " ," 13 " ," 5 " ," /" ," + " ]-> (4+ (13/After this problem is to write a program to calculate the inverse Polish results, iterate expression operand stack encounter, encounter operator to fetch two operands the stack, and then calculated as follows:> 6 Analysis- 5)) The results of the stack, the only remaining operand stack is the final calculations.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
EvaluateReversePolishNotation.cpp