http://pat.zju.edu.cn/contests/pat-a-practise/1073
Scientific notation is the way that scientists easily handle very large numbers or very small. The notation matches the regular expression [+-][1-9] ". [0-9]+e[+-][0-9]+ which means that this integer portion has exactly one digit, there is at least one digit in the Fractiona L portion, and the number and its exponent ' s signs are always provided even when they are.
Now given a real number a in scientific notation, and you are supposed to print a in the conventional notation while keeping a ll the significant figures.
Input Specification:
Each input file contains one test case. For each case, there are one line containing the real number A in scientific notation. The number is no further than 9999 bytes in length and the exponent ' s absolute value is no more than 9999.
Output Specification:
For each test case, print at one line the input number A in the conventional notation and the significant figures ke PT, including trailing zeros, Sample Input 1:
+1.23400E-03
Sample Output 1:
0.00123400
Sample Input 2:
-1.2E+10
Sample Output 2:
-12000000000
Malle an Egg ~ positive number to go ' + ', did not notice that this wasted too much time ~ ~
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main () {
string s, ans = "";
Getline (CIN, s);
if (s[0] = = '-')
ans + = s[0];
int indexe = S.find ("E");
String num = S.substr (1, indexE-1);
char x = S[indexe + 1];
String exp = S.substr (indexe+2, S.size ()-indexE-2);
StringStream SS;
SS << Exp;
int e;
SS >> E;
if (E = = 0) {
cout << ans << num << endl;
return 0;
}
if (x = = ' + ') {
if (E < Num.size ()-2) {
ans = ans + num[0] + num.substr (2, E) + "." + num.substr (E + 2, NUM.S Ize ()-e-2);
else{
ans = ans + num[0] + num.substr (2, Num.size ()-2);
for (int i = 0; i < e-num.size () + 2; i++)
ans + = "0";
}
}
if (x = = '-') {
ans = ans + "0.";
while (e--! = 1)
ans + = "0";
Ans = ans + num[0] + num.substr (2, Num.size ()-2);
}
cout << ans << endl;
return 0;
}