← 返回 citadel 的题目列表Evaluate Reverse Polish Notation with Custom Operators
类型:online_judge
Given a string array tokens representing an expression in Reverse Polish Notation, evaluate the expression. Valid operators are +, -, *, /. Additionally, support custom binary operators that users can dynamically add with their respective operations. If a symbol is a custom operator, use the custom logic to compute the result. Implement a function evaluate(tokens, customOperators) to compute the expression result. Provide reasonable test cases.
Input:
tokens: A comma-separated list of strings representing the reverse Polish expression.
customOperators: A map where keys are custom operator strings and values are the corresponding binary computation logic.
Output: Return the integer result of the expression evaluation.
Examples:
Input: tokens = "1,3,+,2,i", customOperators = {}
Output: 6
Input: tokens = "7,3,%", customOperators = {"%": ModulusOperator}
Output: 1
Example
Input
7,3,%,{}