Exponentiation
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5265 Accepted Submission(s): 1430
Problem Description
Problems
involving the computation of exact values of very large magnitude and
precision are common. For example, the computation of the national debt
is a taxing experience for many computer systems.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input
The
input will consist of a set of pairs of values for R and n. The R value
will occupy columns 1 through 6, and the n value will be in columns 8
and 9.
Output
The
output will consist of one line for each line of input giving the exact
value of R^n. Leading zeros should be suppressed in the output.
Insignificant trailing zeros must not be printed. Don't print the
decimal point if the result is an integer.
Sample Input
95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
Source
Recommend
PrincetonBoy
这题有点难搞,主要是一个大整数的连乘, 刚开始写了一个大整数相乘的函数,发现不对啊!然后就改,调试了挺长时间的,最终AC!觉得有点幸运~~~
View Code
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 int num[10], result[200], len, flag = 0, cnt1; 6 7 int char_to_int( char *s ) 8 { 9 int i, dian = 0, j, jihao; 10 memset(num,0,10*sizeof(int)); 11 len = strlen(s); 12 //printf( "%s\n", s ); 13 //printf( "%d\n", len ); 14 cnt1 = 0; 15 for( j = len - 1; j >= 0; j-- ) 16 if( s[j] == '.' ) 17 jihao = j; 18 19 for( j = len - 1; j > jihao; j-- ) 20 if( s[j] != '0' ) 21 break; 22 //printf( "%d\n", j ) 23 24 25 for( i = j; i >= 0; i--) 26 if( s[i] != '.' ) 27 num[cnt1++] = s[i] - '0'; 28 else 29 dian = j - i; 30 /*for( i = 0; i < cnt1; i++ ) 31 printf( "%d", num[i] ); 32 printf( "\n%d\n", dian );*/ 33 return dian; 34 } 35 int bignummulti( ) 36 { 37 int i, j, temp[200]; 38 memset(temp, 0 ,200*sizeof(int)); 39 for( i = 0; i < len; i++ ) 40 for( j = 0; j < 200; j++ ) 41 temp[i+j] += result[j] * num[i]; 42 43 for( i = 0; i < 200; i++ ) 44 if( temp[i] >= 10 ) 45 { 46 temp[i+1] += temp[i] / 10; 47 temp[i] = temp[i] % 10; 48 } 49 for( i = 0; i < 200; i++ ) 50 result[i] = temp[i]; 51 return 0; 52 } 53 54 int main(int argc, char *argv[]) 55 { 56 int n, dian, i, cnt, j; 57 char s[10]; 58 memset(s,0,sizeof(s)); 59 while( scanf( "%s %d", &s, &n )!=EOF ) 60 { 61 dian = char_to_int( s ) * n; 62 memset(result,0,200 * sizeof(int)); 63 result[0] = 1; 64 for( i = 1; i <= n; i++ ) 65 bignummulti(); 66 67 for( i = 199; i >= 0; i-- ) 68 if( result[i] != 0 ) 69 break; 70 for( j = 0; j < dian; j++ ) 71 if( result[j] != 0 ) 72 break; 73 if( dian > i ) 74 { 75 if( i == -1 ) 76 printf( "0" ); 77 else 78 printf( "." ); 79 cnt = dian - (i + 1); 80 while( cnt-- ) 81 printf( "0" ); 82 for( ; i >= j; i-- ) 83 printf( "%d", result[i] ); 84 } 85 else 86 for( ; i >= j; i-- ) 87 { 88 if( i == dian-1 ) 89 printf( "." ); 90 printf( "%d", result[i] ); 91 } 92 printf( "\n" ); 93 } 94 95 //system("PAUSE"); 96 return 0; 97 }