这份代码提交提示第一行多个回车

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

刚刚用洛谷IDE跑了一下,回车的问题解决了,麻烦点进来的大佬看一眼这份32分代码哪里出错了QwQ ```cpp #include<iostream> #include<cstdio> #include<string> #include<cstring> using namespace std; /* 20+3x=-18 x=-12.667 */ string str; double ans=0,c,v;//常数,字母系数 int mark; int len=0,tmp=0,neg=1; bool foundIt=true; int main(){ // freopen("in.txt","r",stdin); getline(cin,str); len=str.length(); tmp=0; for(int i=0;i<len-1;i++){ if(str[i]=='-'){ if(foundIt) neg=0-neg; tmp*=neg; neg=-1; c+=tmp; tmp=0; }else{ if(str[i]=='+'){ if(foundIt) neg=0-neg; tmp*=neg; neg=1; c+=tmp; tmp=0; }else{ if(str[i]>='0'&&str[i]<='9'){ tmp=tmp*10+str[i]-'0'; }else{ if(str[i]=='='){ foundIt=false; tmp*=neg; neg=1; c+=tmp; tmp=0; }else{ if(str[i]=='\n') continue; mark=str[i]-'a'; if(!foundIt) neg=0-neg; tmp*=neg; neg=1; v+=tmp; tmp=0; } } } } } if(tmp){ tmp*=neg; c+=tmp; } ans=c/v; // cout<<c<<' '<<v<<endl; printf("%c=%.3lf",mark+'a',ans); return 0; } ```
by entity @ 2020-11-05 23:27:19


|