PAT----A1073 Scientific Notation (20point(s))

A1073 Scientific Notation (20point(s))

字符串处理

题意

科学计数法输入,保留有效数字输出,包括末尾的0。

思路

字符串拼接,多试几次就行了。

Sample Input1:

+1.23400E-03

Sample Output1:

0.00123400

Sample Input2:

-1.2E+10

Sample Output2:

-12000000000
#include"bits/stdc++.h"
using namespace std;

int main(){
	freopen("input.txt","r",stdin);
	string s;  cin >> s; // +1.23400E-03
	string s1 = s.substr(1,1) + s.substr(3,s.find('E')-3);// 123400
	string se = s.substr(s.find('E')+1,s.size()-s.find('E')-1);// 03
	int te = stoi(se);//03
	if(te < 0){
		for(int i=0;i<abs(te);i++){
			if(i == abs(te)-1) s1 = "0."+s1;
			else s1 = "0"+s1;
		}
	}else{
		int id = te+1; // '.' suppose to be
		while(s1.size() < id) s1 += "0";
		s1 = s1.substr(0,id) + '.' + s1.substr(id,s1.size()-id);
		if(s1.back() == '.') s1 = s1.substr(0,s1.size()-1);
	}
	if(s[0] == '-') s1 = "-"+s1;
	cout << s1 << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值