POJ 1001 exponentiation (Large power, Java Dafa good! Calls to multiple methods)

Source: Internet
Author: User

exponentiation
Time Limit: 500MS Memory Limit: 10000K
Total Submissions: 156303 Accepted: 38063

Description

Problems involving the computation of exact values of very large magnitude and precision are common. 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 is a real number (0.0 < R < 99.999) and n is a integer such that 0 < n <= 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 line for each line of input giving the exact value of r^n. Leading zeros should is suppress Ed in the output. Insignificant trailing zeros must not being printed. Don ' t print the decimal point if the result was an integer.

Sample Input

95.123 120.4321 205.1234 156.7592  998.999 101.0100 12

Sample Output

548815620517731830194541.899025343415715973535967221869852721.00000005148554641076956121994511276767154838481760200726351 20383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.7641210216181644302 0690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201

Hint

If you don ' t know what to determine wheather encounted the end of input:
sis a string and Nis an integer
C + +while (cin>>s>>n) {...} cwhile (scanf ("%s%d", S,&n) ==2)//to See  If the scanf read on as many items as you Want/*while (scanf (%s%d), s,&n)!=eof)//this also work    */{...}

Source

East Central North America 1988
original title link: http://poj.org/problem?id=1001
Test Instructions: Enter two number x, Y, x^y, (y is integer), the result is less than 0, the result of the output is removed from the previous "0.", the direct output of the back.
this question is similar to the previous one, http://blog.csdn.net/hurmishine/article/details/51008733such as: Striptrailingzeros ()toplainstring ();The method called is similar, but if the result is less than 0, the leading "0" should be removed.?converting the result to a string type and then calling the substring () method in the Java.lang.string class is OK.in the API substring ()description of the method:

Public String substring(int beginindex)returns a new string that is a substring of this string. The substring starts at the character at the specified index,
Until the end of this string.
Example:
"unhappy". SUBSTRING (2) returns "Happy"
"Harbison". SUBSTRING (3) returns "Bison"
"Emptiness". SUBSTRING (9) returns "" (An empty string)
Parameters:
Beginindex-Start index (included).
Return:
The specified substring.
Thrown:
Indexoutofboundsexception-if beginindex is negative or greater than the length of this String object.

substring
Public String substring(int beginindex,int endIndex)returns a new string that is a substring of this string. The substring starts at the specified beginindex until the character at index EndIndex-1. Therefore, the length of the substring is endindex-beginindex.
Example:
"Hamburger". Substring (4, 8) returns "Urge"
"smiles". Substring (1, 5) returns "Mile"
Parameters:
Beginindex-Start index (included).
EndIndex-end index (not included).
Return:
The specified substring.
Thrown:
Indexoutofboundsexception -if beginindex is negative, or endIndex is greater than the length of this String object,or Beginindex greater than endIndex.

AC Code:
Import Java.math.bigdecimal;import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner s c = new Scanner (system.in), while (Sc.hasnext ()) {BigDecimal a = Sc.nextbigdecimal (); int b = Sc.nextint (); a = A.pow (b); String str = A.striptrailingzeros (). toplainstring (); if (Str.startswith ("0.")) {str = str.substring (1);} System.out.println (str);}}}


POJ 1001 exponentiation (Large power, Java Dafa good! Calls to multiple methods)

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.