Skip to content

RPN calculator · ⁨逆波兰计算器⁩

English

RPN calculator

In Reverse Polish Notation the operator comes after its two numbers: 2 3 + means 2 + 3, and 2 3 4 * + means 2 + (3 * 4) = 14. No brackets needed.

Use a stack (a list). Read tokens left to right: push numbers; when you hit an operator, pop the top two, combine them (mind the order — the first value popped is the right-hand side), and push the result. The answer is what's left on top.

中文

逆波兰计算器

在逆波兰表示法中,运算符出现在它的两个数字之后:2 3 + 表示 2 + 3,而 2 3 4 * + 表示 2 + (3 * 4) = 14。不需要括号。

使用一个栈(列表)。从左到右读取记号:遇到数字就压栈;遇到运算符就弹出栈顶两个值,把它们组合起来(注意顺序 —— 先弹出的是右操作数),再把结果压栈。最后留在栈顶的就是答案。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩