Scientific counting is a convenient method used by scientists to express large or small numbers. It satisfies the regular expression [+-][1-9]"," [0-9] + E [+-] [0-9]+, that is, the integer part of a number has only one digit and the decimal part has at least one digit. The positive and negative signs of the number and its exponential part must be clearly given even for positive numbers.
The real number A is given in the form of scientific counting method. Please write a program to output A in the form of ordinary numeric representation, and ensure that all valid bits are preserved.
Input format:
Each input contains a test case, a real number A represented by a scientific counting method. The storage length of the number does not exceed 9999 bytes, and the absolute value of its index does not exceed 9999.
Output format:
For each test case, output A in a row in a normal numeric representation, and ensure that all significant bits are retained, including 0 at the end.
Input Sample 1:
+1.23400E-03
Output Sample 1:
0.00123400
Input Sample 2:
-1.2E+10
Output Sample 2:
-12000000000
Code:
#include <cstdio> #include <cstring> int main() { char str[10010]; //Define an input character array gets(str); int len=strlen(str); //Get its length int i; if(str[0]=='-') printf("-"); //If the first one is -, print it out. int postion=0; //Step 1: Find the location of E first while(str[postion]!='E') { postion++; //Record the location of E } int exp=0; // Step 2: Storage Index for(i=postion+2;i<len;i++) { exp = exp*10 + (str[i]-'0'); } if(exp==0) //Step 3: Determine the index if = 0 { for(i=0;i<postion;i++) { printf("%c",str[i]); //Direct input string } } if(str[postion+1]=='-') //Step 4: If the exponent is negative { printf("0."); //Print 0. first. for(i=0;i<exp-1;i++) //Number of zeros corresponding to reprinting index { printf("0"); } printf("%c",str[1]); //Reprint character array for(i=3;i<postion;i++) //Finally, enter an unexpected number other than the decimal point. { printf("%c",str[i]); } } else //Step 5: If the exponent is positive { for(i=1;i<postion;i++) { if(str[i]=='.') continue; //Go through the numbers before E first printf("%c",str[i]); if(i==exp+2 && postion-3 !=exp) //Reprint the changed. { printf("."); } } for(i=0;i<exp-(postion-3);i++) //If the exponent exp is large, point out the redundant 0 { printf("0"); } } return 0; }
Result: