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 |
高手指点一下,vc中正常运行,但是提交时却是OLE#include <iostream> #include <string> #define max 100 using namespace std; int multiply( int *sum, int *a, int *b, int la, int lb ); int main() { char sr[7]; int a[7], sum[max], b[max]; int n, lsum, la, lb, pos; int i, j, k; while( cin>>sr>>n ) { //chage sr to a la = strlen(sr); for( i = 0, j = la-1 ; j >= 0 ; i++, j-- ) { if( sr[j] == '.' ) { pos = i; i--; } else { a[i] = sr[j] - '0'; sum[i] = a[i]; } }//end for lsum = --la; for( i = 1; i < n; i++) { for( j = 0; j < max; j++ ) { b[j] = sum[j]; sum[j] = 0; }// end first for lb = lsum; lsum = multiply(sum, a, b, la, lb); }//end second for //output the result pos = pos * n; for( i = lsum-1; i >= 0; i--) { if( i == pos-1 ) { cout<<"."; i++; pos = max; } else cout<<sum[i]; } cout<<endl; }//end while return 0; } //function multiply int multiply( int *sum, int *a, int *b, int la, int lb ) { int lsum = 0; int i, j; //initialize the sum for( i = 0; i < max; i++) sum[i] = 0; //mul for( i = 0; i < la; i++ ) for ( j = 0, lsum = i; j < lb; j++ ) sum[lsum++] += a[i] * b[j]; //advance for( i = 0; i < lsum; i++ ) { if( i == lsum -1 && sum[lsum -1] >= 10 ) lsum++; if( sum[i] >= 10 ) { sum[i+1] += sum[i] / 10; sum[i] = sum[i] % 10; } } return lsum; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator