科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+-][0-9]+,即数字的整数部分只有1位,小数部分至少有1位,该数字及其指数部分的正负号即使对正数也必定明确给出。
现以科学计数法的格式给出实数A,请编写程序按普通数字表示法输出A,并保证所有有效位都被保留。
输入格式:
每个输入包含1个测试用例,即一个以科学计数法表示的实数A。该数字的存储长度不超过9999字节,且其指数的绝对值不超过9999。
输出格式:
对每个测试用例,在一行中按普通数字表示法输出A,并保证所有有效位都被保留,包括末尾的0。
输入样例1:+1.23400E-03输出样例1:
0.00123400输入样例2:
-1.2E+10输出样例2:
-12000000000
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
for(string str;cin>>str;){
string num = str.substr(1,str.find_first_of('E')-1);
string index = str.substr(str.find_first_of('E')+2,str.length()-str.find_first_of('E')-2);
int pos_point = num.find_first_of('.');
int index_num=0;
if(str[0] == '-'){
cout<<'-';
}
for(int i =0;i < index.length();i++){
index_num+= pow(10,index.length() - i - 1)*(index[i] - '0');
}
char index_flag = str[str.find_first_of('E')+1];
if(index_flag == '-'){
for(int i = 0;i < index_num;i++){
if(pos_point == 0){
num[0] = '0';
num = "." + num;
}else{
num[pos_point] = num[pos_point - 1];
num[pos_point - 1] = '.';
pos_point--;
}
}
if(pos_point){
cout<<num<<endl;
}else{
cout<<"0"<<num<<endl;
}
}else if(index_flag == '+'){
for(int i =0;i < index_num;i++){
if(pos_point < num.length() - 2){
num[pos_point] = num[pos_point + 1];
num[pos_point + 1] = '.';
pos_point++;
}else if(pos_point == num.length() - 2){
num.erase(pos_point,1);
pos_point = index_num + num.length();
}else{
num = num + "0";
}
}
cout<<num<<endl;
}
}
return 0;
}