没有写注释,惭愧。。。 #include<iostream> #include<string> #define SIZE 300 #include<math.h> using namespace std; int mul(int r[6],int result[SIZE]); int init(string str, int n, int& point,int * r,int * result); int solve(int n, int * r,int * result); int display(int *result,int point); int main() { int n; string str; while(cin>>str>>n) { float R; if(str=="000000") { cout<<0<<endl; continue; } R=atof(str.c_str()); int r[6]={0}; int result[SIZE]={0}; int point=0; init(str,n,point,r,result); solve(n,r,result); display(result,point); cout<<endl; } } int solve(int n, int * r,int * result) { for(int i =1;i<n;++i) { mul(r,result); } return 1; } int display(int *result, int point) { int positionHead,positionTail; for(int i=0;i<SIZE;++i) { if(result[i]!=0) { positionTail=i; break; } } for(int i=SIZE-1;i>=0;--i) { if(result[i]!=0) { positionHead=i; break; } } if(positionHead<positionTail) { cout<<0; } else{ for(int i=positionHead;i>=point;--i) { cout<<result[i]; } if(positionTail<point) { cout<<'.'; } for(int i=point-1;i>=positionTail;--i) { cout<<result[i]; } } return 1; } int init(string str, int n,int& point,int * r,int * result) { point=0; int right[6]={0}; for(int i=0;i<str.size();++i) { if(str.at(i)!='.') { if(point==0){ right[i]=str.at(i)-48; } else{ right[i-1]=str.at(i)-48; } } else { point=6-i; } } for(int i=0;i<6;++i) { r[i]=right[5-i]; } point=point*n; for(int i=0;i<6;++i) result[i]=r[i]; return 0; } int mul(int r[6],int result[SIZE]) { int x,y,z,w; int left[SIZE]; int k=0; int right[6]; for(int i=0;i<6;++i) { right[i]=r[5-i]; } for(;k<SIZE;++k) { left[k]=result[k]; result[k]=0; } int i=0; int j=0; for(i=0;i<6;++i) { for(j=0;j<SIZE;++j) { x = left[j] * r[i]; if(x!=0){ z = x % 10; y = x/10; w = i + j; result[w] += z; if(result[w]==0) { result[w+1] += y + 0; } else { result[w+1] += y + result[w]/10; } result[w] %= 10; if((result[w+1]/10)>0) { result[w+2]=result[w+2]+(result[w+1]/10); result[w+1]=result[w+1]%10; } if((result[w+2]/10)>0) { result[w+3]=result[w+3]+(result[w+2]/10); result[w+2]=result[w+2]%10; } } } } return 0; }