# Poj Solution 1001

```http://poj.org/problem?id=1001

#include <iostream>
#include <string.h>
using namespace std ;

char R[10] , Num[160] ;
int n , L , Point , i , j , l , k ;
int f[160] , c[160] , A[160] ;
int x , y , z , LA , Lf , w ;

int main() {
while ( cin >> R >> n ) {
L = 0 ;
Point = 0 ;
for ( k = 0 ; k < strlen(R) ; k ++ )
if ( R[k] != '0' ) break ;
for ( i = k ; i < strlen(R) ; i ++ )
if ( R[i] == '.' ) break ;
for ( j = strlen(R)-1 ; i < j ; j -- )
if ( R[j] != '0' ) break ;
for ( l = k ; l <= j ; l ++ )
if ( R[l] != '.' )
Num[++L] = R[l] ;
else
Point = j - l ;
for ( i = 1 ; i < 160 ; i ++ ) {
f[i] = 0 ;
c[i] = 0 ;
A[i] = 0 ;
}
f[1] = 1 ;
Lf = 1 ;
LA = 0 ;
for ( j = L ; j >= 1 ; j -- )
A[++LA] = Num[j]-'0' ;
for ( i = 1 ; i <= n ; i ++ ) {
for ( j = 1 ; j <= Lf ; j ++ )
c[j] = 0 ;
for ( j = 1 ; j <= LA ; j ++ )
for ( k = 1 ; k <= Lf ; k ++ ) {
x = A[j] * f[k] ;
y = x / 10 ;
z = x % 10 ;
w = j + k - 1 ;
c[w] += z ;
c[w+1] += (c[w]/10 + y) ;
c[w] %= 10 ;
}
Lf += LA ;
while ( c[Lf] == 0 ) Lf -- ;
for ( j = 1 ; j <= Lf ; j ++ )
f[j] = c[j] ;
}
if ( Lf < Point * n ) {
cout << "." ;
for ( i = Point * n ; i > Lf ; i -- )
cout << "0" ;
}
for ( i = Lf ; i >= 1 ; i -- ) {
if ( i == Point * n ) cout << "." ;
cout << f[i] ;
}
cout << endl ;
}
return 0 ;
}
```
This entry was posted in poj. Bookmark the permalink.