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 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 <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
int i;
char f1,f2;
int nn;
scanf("%c",&f1);
if(f1=='-')
printf("-");
char tc;
vector<char> a;
a.push_back(0);
int m;
while(~scanf("%c",&tc))
{
int t1;
t1=tc;
if( t1==46||(t1>=48&&t1<=57) )
{
if( (t1>=48&&t1<=57) )
{
a.push_back(tc);
}
else
{
m=a.size()-1;
}
}
else if(tc=='E')
break;
}
scanf("%c",&f2);
scanf("%d",&nn);
if(f2=='-')
m-=nn;
else
m+=nn;
if(m==0)
{
printf("0.");
for(i=1;i<a.size();i++)
{
cout<<a[i];
}
}
else if(m<0)
{
printf("0.");
for(i=0;i<-m;i++)
printf("0");
for(i=1;i<a.size();i++)
{
cout<<a[i];
}
}
else if(m>0)
{
if(m==a.size()-1)
for(i=1;i<a.size();i++)
{
cout<<a[i];
}
else if(m<a.size()-1)
{
for(i=1;i<=m;i++)
{
cout<<a[i];
}
printf(".");
for(i=m+1;i<a.size();i++)
{
cout<<a[i];
}
}
else if(m>a.size()-1)
{
for(i=1;i<a.size();i++)
{
cout<<a[i];
}
for(i=0;i<m-(a.size()-1);i++)
printf("0");
}
}
/*
for(i=1;i<a.size();i++)
{
cout<<a[i];
}
printf("\n");
cout<<f2<<nn<<m;
*/
/*
for(i=1;i<=N;i++)
{
for(j=0;j<a[i].size();j++)
cout<<a[i][j]<<' ';
printf("\n");
}
*/
return 0;
}
本文介绍了一种将科学计数法表示的实数转换为常规记数法的方法,并提供了一个C++实现示例,该程序能够正确处理正负号、小数部分及指数部分。
2765

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



