#include <bits/stdc++.h>
using namespace std;
map<char, int> priority = {
{ '+', 1 },{ '-', 1 },{ '*', 2 },{ '/', 2 },{ '(', 0 }
};
vector<string> poststr;
stack<char> op;
void topoststr(string &str) {
string num;
for (int i = 0; i < str.size(); i++) {
if (isdigit(str[i])) {
num.clear();
while (isdigit(str[i])) {
num.push_back(str[i]);
i++;
}
poststr.push_back(num);
--i;
}
else if (str[i] == '(') {
op.push(str[i]);
}
else if (str[i] == ')') {
while (op.top() != '(') {
string tmp;
tmp = op.top();
poststr.push_back(tmp);
op.pop();
}
op.pop();
}
else {
while (!op.empty() && priority[str[i]] &l
2020 SHOPEE笔试题——表达式求值
最新推荐文章于 2021-07-28 16:11:36 发布