zgl_ivy @ 2021-02-04 21:30:41
#include <iostream>
using namespace std;
int main()
{
float a,b,sx;
int ge,shi,bai;
cin>>a;
sx=a-(int)a;
ge=(int)a%10;
shi=((int)a%100)/10;
bai=(int)a/100;
b=10*sx+0.1*ge+0.01*shi+0.001*bai;
cout<<b;
return 0;
}
by _caiji_ @ 2021-02-04 21:38:56
这道题是一道字符串题,像你这样的方法容易因为精度问题而逝世。
by tyw_xx @ 2021-02-04 21:51:37
@zhy20030905
#include <iostream>
using namespace std;
int main()
{
double a,b,sx;
int ge,shi,bai;
cin>>a;
sx=a-(int)a;
ge=(int)a%10;
shi=((int)a%100)*1.0/10;
bai=(int)a*1.0/100;
b=10*sx+0.1*ge+0.01*shi+0.001*bai;
cout<<b;
return 0;
}
by zgl_ivy @ 2021-02-04 21:56:45
@tyw_xx 谢谢大佬!改成double就AC了! 不过为什么要用double?
by zgl_ivy @ 2021-02-04 21:59:44
@caijianhong emmmm用字符串好有道理!我去试试。
其实就是之前我看见数字只想加加减减
by Vanstage @ 2021-02-04 23:38:40
@zhy20030905 似乎是因为double精度高
by zgl_ivy @ 2021-02-05 08:50:30
@泡茶米 似乎是吧。谢谢你啊!