Skip to content · ⁨コンテンツへスキップ⁩

RPN calculator · ⁨RPN計算機⁩

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.

日本語

RPN電卓

逆ポーランド記法では演算子が2つの数値の後に来ます: 2 3 + は 2 + 3 を意味し、 2 3 4 * + は 2 + (3 * 4) = 14 を意味します。 括弧は不要です。

スタック(リスト)を使います。トークンを左から右へ読み進めます: 数はスタックに積みます。演算子に出会うと、上の2つを取り出し、組み合わせます(順序に注意 — 最初に取り出した値が右辺)。結果をスタックに戻します。答えは残ったトップの値です。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP