标签:return str bsp nbsp [] tac code convert public
public class Solution { public int EvalRPN(string[] tokens) { Stack<int> ST_NUM = new Stack<int>(); foreach (var to in tokens) { if (to == "+" || to == "-" || to == "*" || to == "/") { var num1 = ST_NUM.Pop(); var num2 = ST_NUM.Pop(); if (to == "+") { var num = num2 + num1; ST_NUM.Push(num); } else if (to == "-") { var num = num2 - num1; ST_NUM.Push(num); } else if (to == "*") { var num = num2 * num1; ST_NUM.Push(num); } else if (to == "/") { var num = num2 / num1; ST_NUM.Push(num); } } else { var num = Convert.ToInt32(to); ST_NUM.Push(num); } } var result = ST_NUM.Pop(); return result; } }
标签:return str bsp nbsp [] tac code convert public
原文地址:https://www.cnblogs.com/asenyang/p/9826672.html