//Author:Guo R.H
//Date:07.1.6
// USTC
#include
double atof(char a[])
{
int i, sign, p, v, n=1;
double var, pow;
for(i=0; a[i]==' '; i++)
;
sign = a[i]=='-'?-1:1;
if(a[i]=='-' || a[i]=='+')
i++;
for(var=0.0; isdigit(a[i]); i++)
var = var*10 + a[i]-'0';
if(a[i] == '.')
i++;
for(pow=1.0; isdigit(a[i]); i++)
{
var = var*10 + a[i]-'0';
pow *= 10;
}
if(a[i] == 'e')
i++;
p = a[i]=='-'?-1:1;
if(a[i]=='-' || a[i]=='+')
i++;
for(v=0; isdigit(a[i]); i++)
v = v*10 + a[i]-'0';
while(v>0)
{
n *= 10;
v--;
}
if(p == 1)
return sign*var*n/pow;
else
return sign*var/(pow*n);
}
int main()
{
printf("%lf\n", atof(" +0.1453e1"));
return 0;
}
阅读(928) | 评论(0) | 转发(0) |