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.
Sample Input 1:
+1.23400E-03
Sample Output 1:
0.00123400
Sample Input 2:
-1.2E+10
Sample Output 2:
-12000000000
作者: HOU, Qiming
单位: 浙江大学
时间限制: 200 ms
内存限制: 64 MB
#include "pch.h"
#include <iostream>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int main()
{
string a;
cin >> a;
int len = a.length();
int index,f;
char c[10000];
int cnt = 0;
int num = 0;
double radix = 0.1;
for (int i = 0; i < len; i++)
if (a[i] == 'E')
{
index = i;
break;
}
for (int i = 1; i < index; i++)
if (isdigit(a[i]))
c[cnt++] = a[i];
int sign1=0,sign2=0;
if (a[0] == '+')
sign1 = 1;
if (a[index + 1] == '+')
sign2 = 1;
for (int i = 1; i < index; i++)
if (a[i] == '.')
{
f = i;
break;
}
for (int i = index + 2; i < len; i++)
num = num * 10 + a[i] - '0';
//cout << num << endl;
if (sign2 == 0)
{
if (sign1 == 0)
cout << "-";
cout << "0.";
for (int i = 0; i < num - (f- 1); i++)
cout << 0;
for (int i = 0; i < cnt; i++)
cout << c[i];
}
else
{
if (sign1 == 0)
cout << "-";
int m = num - (index-f - 1);
if (m >= 0)
{
for (int i = 0; i < cnt; i++)
cout << c[i];
for (int i = 0; i <m; i++)
cout << 0;
}
else
{
for (int i = 0; i < num + 1; i++)
cout << c[i];
cout << ".";
for (int i = num + 1; i < cnt; i++)
cout << c[i];
}
}
}