显示代码纯文本
#include<stdio.h>
const int MAXN=1000;
char exp[MAXN]={0};
void open(){
freopen("computer.in","r",stdin);
freopen("computer.out","w",stdout);
}
void close(){
fclose(stdin);
fclose(stdout);
}
void read(){
scanf("%s",exp);
}
void solve(){
int x=0,c=0;
int t=0;
int fu=1;
int f=1;
char w;
for(int i=0;exp[i];i++){
if(exp[i]=='+')fu=1*f;
else if(exp[i]=='-')fu=(-1)*f;
else if(exp[i]=='=')fu=f=-1;
else if(exp[i]>='0' && exp[i]<='9'){
while(exp[i]>='0' && exp[i]<='9'){
t*=10;
t+=exp[i++]-'0';
}
t*=fu;
if(exp[i]>='A' && exp[i]<='z'){
x+=t;
w=exp[i];
}
else{
c+=t;
}
i--;
t=0;
}
}
if(!c)printf("%c=%.3f",w,0.0000);
else printf("%c=%.3f",w,(c*(-1.0))/x);
}
int main(){
open();
read();
solve();
close();
}