UVa 748/POJ 1001 exponentiation: Application of power & regular expression of floating-point high precision

Source: Internet
Author: User
Tags integer regular expression time limit

748-exponentiation

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=97&page=show_problem &problem=689

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

Problems involving the computation of exact values of very large magnitude and precision are. For example, the computation of the national debt are a taxing experience for many computer systems.

This problem requires so you write a program to compute the exact value of Rn where R. A real number (0.0 < R < 99.999) and n is a integer such that $ < n le 25$.

Input
The input would consist of a set of pairs of values for R and N. The R value would occupy columns 1 through 6, and the N value would be in columns 8 and 9.

Output
The output would consist of one for each line of input giving the exact value of Rn leading zeros and insignificant t Railing zeros should is suppressed in the output.

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

Description
It is a very common problem to perform high precision calculation on the number of large numbers and high precision. For example, the calculation of national debt is a problem of this sort.

Now the problem for you to solve is: for a real R (0.0 < R < 99.999), a write program is required to accurately compute the n-th (Rn) of R, where n is an integer and 0 < n <= 25.

Input
The T input includes multiple sets of R and N. The values for R are in columns 1th through 6th, and N is in the 8th and 9th columns.

Output
For each set of inputs, the output line is required, which contains the exact n-th side of R. The output needs to get rid of the leading 0 not 0. If the output is an integer, do not output a decimal point.

Complete code:

/*uva:0.242s*/
/*poj:125ms,3340kb*/
    
import java.util.*;  
Import java.math.*;  
Import java.io.*;  
    
public class Main {  
    static Scanner cin = new Scanner (new Bufferedinputstream (system.in));  
    
    public static void Main (string[] args {while  
        (Cin.hasnext ()) {  
            BigDecimal R = Cin.nextbigdecimal ();  
            int n = cin.nextint ();  
            String str = R.POW (n). Striptrailingzeros (). toplainstring ();  
            Returns the string representation of this bigdecimal that removes all trailing zeros, without referring to the number segment  
            if (Str.indexof ("0") < Str.indexof ("."  
                )) str = Str.replacefirst ("^0*", "");  
                ^ matches the start of a string, * means repeat 0 or more times  
            System.out.println (str);}}  

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.