标签:style blog class code java ext
95.123 12 0.4321 20 5.1234 15 6.7592 9 98.999 10 1.0100 12
548815620517731830194541.899025343415715973535967221869852721 .00000005148554641076956121994511276767154838481760200726351203835429763013462401 43992025569.928573701266488041146654993318703707511666295476720493953024 29448126.764121021618164430206909037173276672 90429072743629540498.107596019456651774561044010001 1.126825030131969720661201
1 //@author langx 2 //G++4.4 3 #include <cstdio> 4 #include <cstring> 5 #define SIZE 126 6 #define LEN 5 7 8 int a[SIZE],b[LEN]; 9 10 int mul( int alen,int blen){ 11 int tmp[SIZE], i, j, k; 12 memset(tmp,0,sizeof(tmp)); 13 for( i = 0; i < alen; ++i){ 14 for( j = 0; j < blen; ++j){ 15 tmp[i + j] += a[i] * b[j]; 16 } 17 } 18 k = alen + blen - 1; 19 for( i = 0;i < k; ++i){ 20 if( tmp[i] >= 10){ 21 tmp[ i + 1] += tmp[i] / 10; 22 tmp[i] = tmp[i] % 10; 23 } 24 a[i] = tmp[i]; 25 } 26 a[i] = tmp[i]; 27 if( tmp[k] !=0 )k++; 28 return k; 29 } 30 31 int main(){ 32 char r[LEN + 1]; 33 int n, i, j, len, alen, mark, formark, ok; 34 while( scanf("%s%d",r, &n) == 2 ){ 35 len = strlen(r); 36 mark = 0; 37 for( i = len - 1, j = 0 ; i >= 0 ; --i){ 38 if(r[i]==‘.‘){ 39 mark =i;continue; //记录小数点位置 40 } 41 a[j] = b[j++] = r[i]-‘0‘; 42 } 43 --len; 44 mark = len - mark; 45 alen = len; 46 for( i = 1;i < n; i++){ 47 alen = mul( alen,len); 48 } 49 for( i = 0; i < alen; ++i){ 50 if( a[i] != 0)break; 51 } 52 mark *= n; 53 formark = i; //记录后缀,如70.10000 54 ok = 0; 55 for( i = alen-1; i >= formark; --i){ 56 if( a[i] == 0 && i >= mark && !ok )continue; 57 if( i == mark - 1) printf("."); 58 printf("%d", a[i]); 59 ok = 1; 60 } 61 for(formark--; formark >= mark; --formark){ 62 printf("0"); 63 } 64 printf("\n"); 65 } 66 return 0; 67 }
Poj.Grids 2951 浮点数求高精度幂,布布扣,bubuko.com
标签:style blog class code java ext
原文地址:http://www.cnblogs.com/vivider/p/3716376.html