1073 Scientific Notation (20 分)
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
#include<cstdio>
#include<cstring>
int main()
{
char pon,dot,s[10000],s1[10000],s2[10000];
scanf("%s",s);
int len=strlen(s);
int flag=0,j=0;
for(int i=0;i<len;i++)
{
if(s[i]=='E')
{
flag=1;
continue;
}
if(flag==0)
s1[i]=s[i];
else
s2[j++]=s[i];
}
if(s2[0]=='-')
{
len=strlen(s2);
int sum=0,num1=0;
for(int i=1;i<len;i++)
{
num1=s2[i]-'0';
sum=sum*10+num1;
}
if(s[0]=='-')
printf("-0.");
else
printf("0.");
for(j=1;j<sum;j++)
{
printf("0");
}
len=strlen(s1);
printf("%c",s[1]);
for(j=3;j<len;j++)
{
printf("%c",s1[j]);
}
}
else
{
if(s[0]=='-')
printf("-%c",s1[1]);
else
printf("%c",s1[1]);
len=strlen(s2);
int sum=0,num1=0;
for(int i=1;i<len;i++)
{
num1=s2[i]-'0';
sum=sum*10+num1;
}
len=strlen(s1);
int count=0;
int sum1=sum;
for(j=3;j<len;j++)
{
printf("%c",s1[j]);
count++;
if(sum1==1&&j!=len-1)
printf(".");//忘记输出点了
sum1--;
}
for(int i=0;i<sum-count;i++)
{
printf("0");
}
}
return 0;
}