题目描述
Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent’s signs are always provided even when they are positive.
Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.
Input Specification:
Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent’s absolute value is no more than 9999.
Output Specification:
For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.
科学计数法是科学家轻松处理非常大或非常小的数字的方式。
这种表示法与正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+ 相匹配。
整数部分恰好一位,小数部分至少一位,数字以及指数的正负必须给出,即使均为正,也要给出 +。
现在给定科学计数法表示的实数 A,请你在保留所有有效数字的情况下以常规计数法输出 A。
输入格式
共一行,包含科学计数法表示的实数 A。
输出格式
输出常规计数法表示的 A,注意保留所有有效数字,包括尾部 0。
数据范围
输入数字的长度不超过 9999 字节,指数的绝对值不超过 9999。
Sample Input 1:
+1.23400E-03
Sample Output 1:
0.00123400
Sample Input 2:
-1.2E+10
Sample Output 2:
-12000000000
// the regular expression正则表达式 Scientific notation科学记数法
//notationn.符号; (数学、科学和音乐中的)记号; 谱号
//the conventional notation传统符号 exponent指数 bytes字节
//The number is no more than 9999 bytes in length
//and the exponent's absolute value is no more than 9999.
//该数字的长度不超过9999个字节,指数的绝对值不大于9999。
//For each test case, print in one line the input number A in the conventional notation,
//with all the significant figures kept, including trailing zeros.
//对于每个测试用例,在一行中打印传统符号中的输入数字A,保留所有有效数字,包括尾随零。
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
if(s[0] == '-') cout<<'-';
int k = s.find("E");
//+1.23400E-03 中 取出 123400
//并且将会转化成 0.123400
string a = s[1] + s.substr(3,k-3);
int b = stoi(s.substr(k+1));
b++;//小数点向左移动一位,缩小十倍,b++
//+1.23400E-03 -> 0.00 123400
if(b<=0) a = "0."+string(-b,'0')+a;
//-1.2E+10 -> -12 000 000 000
else if(b>=a.size()) a+=string(b-a.size(),'0');
//+1.234E2 -> 123.4
else a = a.substr(0,b)+'.'+a.substr(b);
cout<<a;
return 0;
}