#include #include #include using namespace std;

int main() { string infix; cin >> infix;

stack<char> op_stack;
string postfix = "";

for (char c : infix) {
    if (isdigit(c)) {
        postfix += c;
    } else {
        while (!op_stack.empty() && op_stack.top() != '(' && ((c == '*' || c == '/') || (op_stack.top() == '+' || op_stack.top() == '-'))) {
            postfix += op_stack.top();
            op_stack.pop();
        }
        op_stack.push(c);
    }
}

while (!op_stack.empty()) {
    postfix += op_stack.top();
    op_stack.pop();
}

cout << postfix << endl;
return 0;

}


原文地址: https://www.cveoy.top/t/topic/oiLU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录