| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Why wrong!请牛人们帮忙看看!#include<stdio.h>
#include<string.h>
void mult(int *a,int *b,int *c)
{//c=a*b;
int i,j,m,n,k;
m=a[0];n=b[0];
k=n+m-1;
for(i=0;i<=k;i++)c[i]=0;
for(i=1;i<=m;i++)
{if(a[i])for(j=1;j<=n;j++)if(b[j])c[i+j-1]+=a[i]*b[j];
}
for(i=k;i>=1;i--)
if(c[i]>9){c[i-1]+=c[i]/10;c[i]%=10;}
if(c[0]>0)
{k++; for(i=k;i>=1;i--)c[i]=c[i-1]; }c[0]=k;
// for(i=0;i<=k;i++)b[i]=c[i];
}
int main()
{int a[2000],b[2000],c[4000];
int n,i,j,k,l,t;
char ch[2000];
while(scanf("%s%d",ch,&n)!=EOF)
{l=strlen(ch);
for(i=l-1;i>=0;i--)
if(ch[i]=='.'){t=i;break;}
//printf("t=%d\n",t);
if(t==0)
{for(j=0,i=0;i<l;i++)
a[++j]=b[j]=ch[i]-'0';
a[0]=j;
//printf("%d ",a[i]);
}
else
{for(i=l-1;i>=t;i--)
if(ch[i]!='0')break;
t=i-t;
//printf("t0=%d\n",t);
for(k=0,j=0;j<=i;j++)
{ if(ch[j]=='.')continue;
a[++k]=b[k]=ch[j]-'0';
//printf("%d ",b[k]);
}
a[0]=b[0]=k;
}
for(i=1;i<n;i++)
{ mult(a,b,c);
for(j=0;j<=c[0];j++)b[j]=c[j];
}
for(i=1;i<=b[0];i++)
{if(i==b[0]-t*n+1)
printf(".");
if(i==1&&b[i]==0)continue;
printf("%d",b[i]);
}
printf("\n");
}
}
/*
95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
1.126825030131969720661201
*/
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator