先放一下我的ACcode(不是讨论区题解)
#include<bits/stdc++.h>
using namespace std;
string solu(int a,int b,int op)
{
int ans;
string rt="";
if(op==1)ans=a+b;
if(op==2)ans=a-b;
if(op==3)ans=a*b;
if(ans==0)return "0";
if(ans<0)rt="-",ans=-ans;
int ps=1;//here 1
while(ps<=ans)ps*=10;
ps/=10;
while(ps>=1)
{
rt+=(ans/ps)%10+'0';
ps/=10;
}
return rt;
}
char opt[5];
int n,op;
string str;
int main()
{
opt[1]='+';opt[2]='-';opt[3]='*';
cin>>n;
getchar();
getchar();//here 2
for(int j=1;j<=n;j++)
{
int st=0;
getline(cin,str);
if(str[0]=='a')op=1,st=2;
if(str[0]=='b')op=2,st=2;
if(str[0]=='c')op=3,st=2;
int a=0,b=0,i;
string ans="";
for(i=st;;i++)
{
if(str[i]<'0'||str[i]>'9')break;//here 3
a*=10;
a+=(str[i]-'0');
ans+=str[i];
}
i++;
ans+=opt[op];
for(;i<str.size()&&str[i]!='\n'&&str[i]!='\r';i++)
{
b*=10;
b+=(str[i]-'0');
ans+=str[i];
}
ans+='=';
ans+=solu(a,b,op);
cout<<ans<<endl<<ans.size()<<endl;
}
return 0;
}
提示部分:
注释一的位置不能用log算数字位数,会有浮点数误差(可能只有我这么干)

注释二的地方需要两个getchar,因为本题目数据可能在windows下制造。
问题部分:
注释一的位置如果非要用log有无避免浮点数误差的好方法?
注释二的地方有无合适的替换来做到读入整行string?以及能否讲解一下什么时候getline前需要getchar和需要几个?
注释三的地方改成 str[i]==' ' 就会RE,表现为循环不停止,为什么?
质疑部分:
关于本题数据:
第一,作为一个字符串题目,数据在windows下制造会极大影响做题感觉,是否应当替换?
第二,本题的题解有几篇是错的,(VenusM1nT大佬和与他做法类似的几篇)
hack:
2
a 114 514
1 2
原理是只有两个数时,第一个数有可能一位。
个人认为没有因为这个hack撤题解的价值,放在评论区供后人考察
希望后人能从提示中获益,当然也希望能有大佬能来解答我的问题或处理我的质疑
感激不尽。