没有用前缀表达式,用的中缀硬算的哈哈哈哈。

#include <cctype>
#include <cstddef>
#include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;


void clear(stack<char>& opt, stack<long long>& data) {
    while (!opt.empty() && opt.top() != '(') {
        char op = opt.top();
        opt.pop();
        long long a = data.top();
        data.pop();
        long long b = data.top();
        data.pop();
        if (op == '+') {
            long long c = a + b;
            data.push(c);
        } else if (op == '*') {
            long long c = a * b;
            data.push(c);
        }
    }
}


long long fun(string& present, long long x) {
    stack<char> opt;
    stack<long long> data;
    for (int i = 0; i < present.size(); i++) {
        // 如果拿到的是"("
        if (present[i] == '(') opt.push('(');
        // 如果拿到的是")"
        if (present[i] == ')') {
            clear(opt, data);
            if (!opt.empty()) opt.pop();
            if (i != present.size() - 1 && present[i + 1] == '(') opt.push('*');
        }
        // 如果拿到的是 *
        if (present[i] == '*') opt.push('*');
        // 如果拿到的是 +
        if (present[i] == '+') {
            if (!opt.empty() && opt.top() == '*') {
                clear(opt, data);
            }
            opt.push('+');
        }
        // 如果拿到的是 数字
        if (isdigit(present[i])) {
            // 判断前方
            if (i != 0 && (present[i - 1] == 'x' || present[i - 1] == ')')) opt.push('*');

            string t = "";
            while (isdigit(present[i])) {
                t += present[i++];
            }
            i--;
            long long d = stoll(t);
            data.push(d);
            // 判断后方
            if (i != present.size() - 1 && (present[i + 1] == 'x' ||
                                            present[i + 1] == '(')) opt.push('*');
        }
        // 如果拿到的是 x
        if (present[i] == 'x') {
            // 判断前方
            if (i != 0 && present[i - 1] == ')') opt.push('*');
            data.push(x);
            if (i != present.size() - 1 && present[i + 1] == '(') opt.push('*');
        }
    }

    if(!opt.empty()){
        clear(opt, data);
    }

    long long res = data.top();
    return res;
}


void solve(string& present, long long& y) {
    long long x1 = 10;
    long long x2 = 20;
    long long y1 = fun(present, x1);
    long long y2 = fun(present, x2);

    long long k = (y2 - y1) / (x2 - x1);
    if (k != 0) {
        long long x = (y - y1) / k + x1;
        cout << x;
    } else cout << "k = 0";
}


int main() {
    string line;
    getline(cin, line);

    size_t pos = line.find("=");

    string left_expr = line.substr(0, pos);
    string right_expr = line.substr(pos + 1);

    long long y = stoll(right_expr);

    solve(left_expr, y);

    return 0;
}