Question:http://poj.org/problem?id=1001
1 #include <iostream> 2 using namespace std; 3 #define max 1000 4 char a[max]; 5 char b[max]; 6 char c[max]; 7 int main() 8 { 9 memset(a,0,1000*sizeof(char)); 10 memset(b,0,1000*sizeof(char)); 11 memset(c,0,1000*sizeof(char)); 12 char *R=(char *)malloc(6*sizeof(char)); 13 int n,point; 14 while(cin>>R>>n) 15 { 16 for(int i=5,j=0;i>=0;i--,j++) 17 { 18 if(R[i]=='.') 19 { 20 point=5-i; 21 j--; 22 continue; 23 } 24 a[j]=R[i]; 25 b[j]=R[i]; 26 } 27 28 if(n==1) 29 { 30 strcpy(c,a); 31 } 32 else 33 { 34 for(int k=1;k<n;k++) 35 { 36 int alen=strlen(a); 37 int blen=strlen(b); 38 int m,n; 39 int jw=0; 40 for(m=0;m<alen+blen;m++) 41 { 42 int temp=0; 43 for(n=((m-blen+1)>0?(m-blen+1):0);n<alen&&m-n<blen&&m-n>=0;n++) 44 { 45 temp+=(a[n]-'0')*(b[m-n]-'0'); 46 } 47 temp+=jw; 48 jw=temp/10; 49 temp%=10; 50 c[m]=temp+'0'; 51 } 52 strcpy(a,c); 53 } 54 } 55 int slen=strlen(c); 56 int q; 57 for(q=strlen(c)-1;c[q]=='0'&&q>=point*n;q--) 58 { 59 c[q]=0; 60 } 61 for(q=0;c[q]=='0'&&q<point*n;q++) 62 { 63 } 64 for(int p=strlen(c)-1;p>=q;p--) 65 { 66 if(p==point*n-1) 67 { 68 cout<<"."; 69 } 70 cout<<c[p]; 71 } 72 memset(a,0,1000*sizeof(char)); 73 memset(b,0,1000*sizeof(char)); 74 memset(c,0,1000*sizeof(char)); 75 cout<<endl; 76 } 77 return 0; 78 }