求大佬帮忙看下问题在哪

P1022 [NOIP2000 普及组] 计算器的改良

‮[@Lv1000](/space/show?uid=93249)
by 夏义博 @ 2018-10-31 19:59:57


^ _ ^
by 夏义博 @ 2018-10-31 20:00:21


@[Lv1000](/space/show?uid=116532) ``` #include<bits/stdc++.h> using namespace std; string s; double lt,rt; int u[3],n[3],k,t=0,alp; void cal(bool kind) { int tmp=0; bool flag=0; while('0'<=s[k]&&s[k]<='9'){ flag=1; tmp=tmp*10+s[k]-'0'; k++; } if(!flag)tmp=1; if(kind)tmp=-tmp; if('a'<=s[k]&&s[k]<='z'){ u[t]+=tmp; alp=k; k++; } else n[t]+=tmp; } int main() { cin>>s; for(k=0;k<s.length();){ if(s[k]=='='){ t=1; k++; continue; } if(s[k]=='-'){ k++; cal(1); } else{ if(s[k]=='+')k++; cal(0); } } lt=n[0]-n[1]; rt=u[1]-u[0]; printf("%c=%.3lf\n",s[alp],lt/rt); return 0; } ```
by 夏义博 @ 2018-10-31 20:39:02


47不到的代码。
by 夏义博 @ 2018-10-31 20:39:24


|