http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28517
Idea: (1) First preprocessing, speaking of the input decimal at the end of the 0 minus, and record the position of the decimal point, and then flashback stored in the array,
(2) A multiplication operation, two cycles.
It is important to note that the length of the array after the operation needs to be accurately recorded.
#include <stdio.h>#include<string.h>#defineN 200voidAdd ();intreverse ();voidSumm ();intSum[n],b[n],n,time[n];CharA[n];intl,len,k;intMain () { while(SCANF ("%s%d", a,&n)! =EOF) {L=0; memset (b,0,sizeof(b)); memset (SUM,0,sizeof(sum)); //memset (time,0,sizeof (time));l=len=k=strlen (a); intflag=reverse (); for(intI=1; i<n;i++) {Add (); Summ ();}intf=0; for(inti=l-1; i>=0; i--){ if(i==n* (Len-flag)-1) {printf ("."); } if(sum[i]==0&&f==0&&i>=n* (len-flag)) { Continue; } f=1; /*if (f==0) {if (sum[i]==0&&i>=n* (Len-flag)) continue; else{f==1; } }*/printf ("%d", Sum[i]);} printf ("\ n");}return 0;}intreverse () {intflag=0; intt=0; K=0; for(inti=len-1; i>=0; i--){ if(a[i]=='.') {flag=i;t=1; Continue; } if(a[i]=='0'&&t==0){ Continue; } t=1; B[K]= sum[k]=a[i]-'0'; K++; } /*for (int i=0;i<len-1;i++) {printf ("%d", sum[i]); } printf ("\n%d\n", flag);*/Len=K; returnFlag;}voidAdd () {memset (time,0,sizeof(time)); for(intI=0; i<l;i++){ for(intj=0; j<len+1; j + +) {Time[i+j]+=sum[i]*B[j]; } } for(intI=0; i<l+len;i++) {Sum[i]=Time[i]; } /*for (int i=0;i<len+l-1;i++) {printf ("%d", sum[i]); } printf ("\ n");*/}voidSumm () {L+=len-1; for(intI=0; i<l;i++){ ints=Sum[i]; if(s>=Ten) {Sum[i]=s%Ten; Sum[i+1]+=s/Ten; if(i==l-1) {L++; Break; } } }}
exponentiation--the power of decimals