codeforces 697B. Barnicle - 字符串变数字

科学计数法 给出 a.deb 的形式 转化为数字 要考虑的情况真的好多 QAQ


#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#include <algorithm>
using namespace std;
#define PI 3.1415926 
int main()
{
	string str;
	int se,sd,ss,sq,j;//e ,点 ,e后数字
	while (getline(cin,str))
	{
		sd = str.find('.',0);
		se = str.find('e',0);
		sq = se+1;
		ss = 0;
		/********************************/
		while (sq<str.length())
		{
			ss*=10;
			ss+=str[sq]-'0';      //【字符串变数字】
			sq++;
		}
		/********************************/
		str.erase(sd,1);
		str = str.substr(0,se-1); //删除e的后续
		j = 0;
		while (str[j] == '0') 
			j++;
		if(j == str.length()){  //0.0e0 的情况
			cout<<'0'<<endl;
			continue;
		}
		if(ss+sd<str.length())  //8.77056e6
		str.insert(ss+sd,1,'.');

		while ( str[str.length()-1] == '0' || str[str.length()-1] == '.' )
			str.erase(str.length()-1,1);  //2.0000e3

		if (str.length()-sd<=ss)  {//末尾补零 2.0e4
			int m = ss-str.length()+sd-1;
			for (int i = 0; i <= m; i++){
				str+='0';
			}
		}
		j = 0;
		while (str[j] == '0' && str[j+1]!='.')//0.0023e0
		j++;
		str = str.substr(j,str.length());
		cout<<str<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值