Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=1063

高精度

我的代码
 1 #include <stdio.h>
2 #include <string.h>
3
4 const int base=10;
5 int a[200],b[10];
6 void mult2(int *a,int *b)
7 {
8 int i,j;
9 for (i=a[0];i>0;i--)
10 {
11 for (j=b[0];j>1;j--) a[i+j-1]+=a[i]*b[j];
12 a[i]*=b[1];
13 }
14 a[0]+=b[0];
15 for (i=1;i<a[0];i++)
16 {
17 a[i+1]+=a[i]/base;
18 a[i]%=base;
19 }
20 if (a[a[0]]==0) a[0]--;
21 }
22 int main()
23 {
24 char aa[10];
25 int n,i,p;
26 while (scanf("%s%d",aa,&n)!=EOF)
27 {
28 memset(a,0,sizeof(a));
29 memset(b,0,sizeof(b));
30 p=0;
31 for (i=5;i>=0;i--)
32 if (aa[i]!='.') b[++b[0]]=aa[i]-'0';
33 else p=5-i;
34 while (b[0]>1 && b[b[0]]==0) b[0]--;
35 a[0]=a[1]=1;
36 for (i=1;i<=n;i++) mult2(a,b);
37 p*=n;
38 for (i=a[0];i>p;i--) printf("%d",a[i]);
39 int t=1;
40 while (t<=p && a[t]==0) t++;
41 if (p>=t)
42 {
43 printf(".");
44 for (i=p;i>=t;i--) printf("%d",a[i]);
45 }
46 printf("\n");
47 }
48 return 0;
49 }

 

posted on 2011-12-03 17:54  Qiuqiqiu  阅读(197)  评论(0编辑  收藏  举报