stack--oj2
链接: link
using namespace std;
class Solution {
public:int evalRPN(vector<string>& tokens) {stack <int> a;for (auto& b : tokens){if (b == "+")//如何操作str!=char??{int right = a.top();a.pop();int left = a.top();a.pop();a.push(right + left);}else if (b == "-")//如何操作str!=char??{int right = a.top();a.pop();int left = a.top();a.pop();a.push(left - right);}else if (b == "*")//如何操作str!=char??{int right = a.top();a.pop();int left = a.top();a.pop();a.push(right * left);}else if (b == "/")//如何操作str!=char??{int right = a.top();a.pop();int left = a.top();a.pop();a.push(left / right);}else{a.push(stoi(b));}}return a.top();}
};