去掉末尾无效0的算法

高精度问题中去掉末尾无效0的C++算法

仅供参考

 
  
#include < iostream >
#include
< string >
using namespace std;

int main()
{
string s;
while (cin >> s)
{
int posdot;
posdot
= ( int )s.find( '. ' );
int count = ( int )s.size() - 1 ;
while (s[count] == ' 0 ' && count >= posdot)
{
count
-- ;
}
s
= (s[count] == ' . ' ) ? s.substr( 0 ,count):s.substr( 0 ,count + 1 );
cout
<< s << endl;
}
system(
" PAUSE " );
}

测试数据:

200000.0000001110000525554112000
200000.0000001110000525554112
225544444448885.000000
225544444448885
45969464546546546545
45969464546546546545
41654651654984664646.000222219465165
41654651654984664646.000222219465165
1654651654654654654654654.0
1654651654654654654654654

转载于:https://www.cnblogs.com/tsingroo/archive/2011/05/13/2045793.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值