RPN calculator · RPN 계산기
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 3 +은 2 + 3을 의미하며, 2 3 4 * +은 2 + (3 * 4) = 14을 의미합니다. 괄호는 필요 없습니다.
스택(목록)을 사용합니다. 토큰을 왼쪽에서 오른쪽으로 읽습니다: 숫자는 밀고(push), 연산자를 만나면 상단 두 개를 빼내 combining(순서 주의 — 먼저 뺀 값이 우변임), 결과를 밀고합니다. 답은 택 위에 남은 것입니다.
Write rpn_eval(tokens) that evaluates a list of Reverse Polish Notation tokens — integers written as strings and the operators +, -, *, /. Use a stack; / should truncate toward zero. Return the final integer. · rpn_eval(tokens)를 작성하여 Reverse Polish Notation 토큰列表를 평가하십시오 — integers는 문자열로, 연산자는 +, -, *, /입니다. 스택(stack)을 사용하십시오; /은 제로 쪽으로 반올림(truncate toward zero)해야 합니다. 최종 integer를 반환하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.