Poj1001 (high-precision multiplication)

Source: Internet
Author: User

1. Question description

Exponentiation
Time limit:500 ms   Memory limit:10000 K
Total submissions:135893   Accepted:33256

Description

Problems involving the computation of exact values of very large magnstrap and precision are common. For example, the computation of the national debt is a taxing experience for your 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.

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 shocould 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 120.4321 205.1234 156.7592  998.999 101.0100 12

Sample output

548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201

Hint

If you don't know how to determine wheather encounted the end of input: SIs a string and NIs an integer
C++ while(cin>>s>>n) { ... } c while(scanf("%s%d",s,&n)==2) //to  see if the scanf read in as many items as you want /*while(scanf(%s%d",s,&n)!=EOF) //this also work    */ { ... }

2. Questions

Return n ^ r to N, R.

3. Solution

High-Precision multiplication or Java big integer class

4. Code:

1 # include <iostream> 2 # include <cmath> 3 # include <algorithm> 4 # include <cstring> 5 # include <cstdio> 6 # define debug 0 7 using namespace STD; 8 void Chen (char a [], char B []) 9 {10 int I, J, K, L, sum, C [410] = {0 }; 11 L = strlen (A) + strlen (B); 12 for (I = strlen (B)-1; I> = 0; I --) 13 For (j = strlen (a)-1, K = I + J + 1; j> = 0; j --, k --) {14 Sum = (B [I]-'0') * (a [J]-'0') + C [k]; 15 C [k] = sum % 10; C [k-1] + = sum/10; 16} 17 for (I = C [0]? 0: 1, j = 0; I <L; I ++) 18 A [J ++] = (C [I] + '0 '); 19 A [J] = 0; 20} 21 int main () 22 {23 int R, N, I, j, point, Len, D; 24 char s [2, 100], s1 [100], C [1000000]; 25 while (scanf ("% S % d", & S, & N )! = EOF) {26 point = 0; 27 Len = strlen (s); 28 memset (S1, 0, sizeof (S1); 29 I = 0; 30 While (s [I] = '0' & I <Len) {// This Is Not preprocessed at the beginning. 31 I ++ is hung on 0000 1; 32} 33 D = 0; 34 while (I <= Len) {35 s [d] = s [I]; 36 I ++; 37 d ++; 38} 39 Len = strlen (s); 40 while (s [point]! = '. '& Point <Len) {41 point ++; 42} 43 I = point; 44 While (I <Len) {45 s [I] = s [I + 1]; 46 I ++; 47} 48 point = len-point-1; 49 point = point * n; 50 if (n! = 0) {51 strcpy (C, S); 52 for (I = 2; I <= N; I ++) {53 Chen (C, S ); 54} 55 I = point; 56 Len = strlen (c); 57 D = 0; 58 While (s [d] = '0' & D <Len) {59 D ++; 60} 61 If (d >=len) {printf ("0");} else 62 if (I> len-d) {63 printf (". "); 64 for (j = 1; j <= I-(LEN-d); j ++) {65 printf (" 0 "); 66} 67 Len = len-1; 68 while (C [Len] = '0') {69 Len --; 70} 71 for (I = D; I <= Len; I ++) {72 printf ("% C", C [I]); 73} 74} else if (I = len-d) {75 printf (". "); 76 Len = len-1; 77 while (C [Len] = '0') {78 Len --; 79} 80 for (I = D; I <= Len; I ++) {81 printf ("% C", C [I]); 82} 83} else {84 I = len-I; 85 Len = len-1; 86 while (C [Len] = '0') {87 Len --; 88} 89 for (j = D; j <I + D; j ++) {90 printf ("% C", C [J]); 91} 92 93 If (LEN> = J) {// The error 0010.00 1 is returned. ", it will be fine after the change. 94 printf (". "); 95 for (j = I + D; j <= Len; j ++) {96 printf (" % C ", C [J]); 97} 98} 99} 100 printf ("\ n"); 101} else {102 printf ("1 \ n"); 103} 104} 105 return 0; 106}

 

Poj1001 (high-precision multiplication)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.