```
#include<iostream>
#include<iomanip>
using namespace std;
bool number(char a){
if(a>='0' && a<='9'){
return true;
}return false;
}
bool xyz(char a){
if(!number(a) && a!='+' && a!='-' && a!='='){
return true;
}return false;
}
int main(){
string s,w;
char a = '+';
int res = 0,x = 0,flag = 1;
cin >> s;
for(int i = 0;i < s.length();++i){
if(number(s[i])){
int num = s[i]-48,p = i+1;
while(number(s[p])&&p<s.length()){
num = num*10+s[p]-48;
p++;
}
if(xyz(s[p]) && p<s.length()){
if(flag){
if(a == '+'){
x += num;
}else{
x -= num;
}
}else{
if(a == '+'){
x -= num;
}else{
x += num;
}
}string str;
while(xyz(s[p])&&p<s.length()){
str += s[p];
p++;
}w = str;
}else{
if(flag){
if(a == '+'){
res -= num;
}else{
res += num;
}
}else{
if(a == '+'){
res += num;
}else{
res -= num;
}
}
}i = p-1;
}else if(s[i] == '='){
flag = 0;
a = '+';
}else if(s[i]=='+' || s[i]=='-'){
a = s[i];
}else if(xyz(s[i])){
if(flag){
if(a == '+'){
x += 1;
}else{
x -= 1;
}
}else{
if(a == '+'){
x -= 1;
}else{
x += 1;
}
}string str;
int p = i;
while(xyz(s[p])&&p<s.length()){
str += s[p];
p++;
}w = str;
i = p-1;
}
}if(res == 0 || x == 0) cout << w << "=0.000";
else cout << w << "=" << fixed << setprecision(3) << res*1.0/x;
return 0;
}
```
宋雨轩,认得我吧?
by hnxxwpf @ 2023-11-25 19:23:49