#include <iostream>
#include <string>
 
using namespace std;
 
string t;
int l, r, x/*未知数系数和*/, n/*常量和*/, mid;
int main() {
    cin >> t;
    x = 0;
    while (t[mid] != '=') mid++; //找到等号
    for (int i = 0; i < t.length(); i++)//寻找未知数并输出
        if (t[i] >= 'a' && t[i] <= 'z') {
            cout << t[i] << '=';
            break;
        }
 
    //处理未知数系数为一的情况
    if (t[0]>='a'&&t[0]<='z') {
        t[0]=0;
        x++;
    }
    if (t[mid+1]>='a'&&t[mid+1]<='z') {
        t[mid+1]=0;
        x++;
    }
 
    for (int i=0; i < mid; i++) {
        if (t[i] >= '0' && t[i] <= '9') {
            l = r = i;
            while (t[r+1] >= '0' && t[r+1] <= '9') r++;
            if (r < t.length())
                if (t[r+1] >= 'a' && t[r-1] <= 'z') {
                    if (l == 0) {
                        x += atoi(t.substr(l, r-l+1).c_str());
                        for (int k = l; k <= r; k++) t[k] = 0;
                    }
                    else {
                        if (t[l-1] == '-')
                            x -= atoi(t.substr(l, r - l + 1).c_str());
                        else
                            x += atoi(t.substr(l, r - l + 1).c_str());
                        for (int k=l-1; k <= r; k++) t[k] = 0;
                    }
                    continue;
                }
            if (l == 0) {
                n -= atoi(t.substr(l, r-l+1).c_str());
                for (int k = l; k <= r; k++) t[k] = 0;
            }
            else {
                if (t[l-1] == '-')
                    n += atoi(t.substr(l, r - l + 1).c_str());
                else
                    n -= atoi(t.substr(l, r - l + 1).c_str());
                for (int k=l-1; k <= r; k++) t[k] = 0;
            }
        }
    }
 
    //注意等号左右未知数系数与常量的加减情况是相反的
    for (int i=mid+1; i < t.length(); i++) {
        if (t[i] >= '0' && t[i] <= '9') {
            l = r = i;
            while (t[r+1] >= '0' && t[r+1] <= '9') r++;
            if (r < t.length())
                if (t[r+1] >= 'a' && t[r-1] <= 'z') {
                    if (l == 0) {
                        x -= atoi(t.substr(l, r - l + 1).c_str());
                        for (int k = l; k <= r; k++) t[k] = 0;
                    }
                    else {
                        if (t[l-1] == '-')
                            x += atoi(t.substr(l, r - l + 1).c_str());
                        else
                            x -= atoi(t.substr(l, r - l + 1).c_str());
                        for (int k = l - 1; k <= r; k++) t[k] = 0;
                    }
                    continue;
                }
            if (t[l-1] == '-')
                n -= atoi(t.substr(l, r - l + 1).c_str());
            else
                n += atoi(t.substr(l, r - l + 1).c_str());
            for (int k = l - 1; k <= r; k++) t[k] = 0;
        }
    }
    printf("%.3lf", double(n) / x);
    return 0;
}

 

posted on 2024-05-04 08:12  爱吃泡面的皮卡  阅读(71)  评论(0编辑  收藏  举报