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 file 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-03Sample Output 1:
0.00123400Sample Input 2:
-1.2E+10Sample Output 2:
-12000000000
代码#include <iostream> #include <string> using namespace std; int main(){ //freopen("in.txt","r",stdin); string raw; cin>>raw; if (raw[0] == '-') cout<<'-'; string s(raw.begin() + 1, raw.end()); int lens = s.length(); string s1(s.begin(), s.begin() + 1); int pose = s.find('E'); string s2(s.begin() + 2, s.begin() + pose); int lens2 = s2.length(); int flag = 1; if (s[pose + 1] == '-') flag = -1; string s3(s.begin() + pose + 2, s.end()); int exp = 0; int lens3 = s3.length(); for (int i = 0; i < lens3; i++) { exp *= 10; exp += s3[i]-'0'; } if (exp == 0) cout << s1 << "." << s2; else { if (flag == 1) { if (exp == lens2) cout << s1 << s2; else if (exp > lens2) { cout << s1 << s2; int zeros = exp - lens2; for (int i = 0; i < zeros; i++) cout << "0"; } else { cout << s1; for (int i = 0; i < exp; i++) cout << s2[i]; cout << "."; for (int j = exp; j < lens2; j++) cout << s2[j]; } } else { cout << "0."; int zeros = exp - 1; for (int i = 0; i < zeros; i++) cout << "0"; cout << s1 << s2; } } cout << endl; return 0; }
本文介绍了一种将科学计数法表示的数字转换为常规计数法的方法,并提供了一个具体的编程实现案例。输入是一个科学计数法形式的实数,输出则是该数值的常规计数法形式,保留所有有效数字。
2745

被折叠的 条评论
为什么被折叠?



