Exponentiation HDU 1063 Java

Source: Internet
Author: User

// Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1063
Import java. Io. *; // 2270586 2010-03-31 00:23:08 accepted 1063 234 Ms 7852 K 559 B Java regret
Import java. util .*;
Import java. Math .*;

Public class main
{
Public static void main (string [] ARGs)
{
Bigdecimal A, sum;
Int I, N;
Cin = new partition (system. In );
While (CIN. hasnext ())
{
A = cin. nextbigdecimal ();
N = cin. nextint ();
Sum = bigdecimal. valueof (1 );
For (I = 0; I <n; I ++)
Sum = sum. Multiply ();
Sum = sum. striptrailingzeros (); // remove unnecessary 0 at the end of striptrailingzeros ()
// Toplainstring () returns a non-exponential string
String STR = sum. toplainstring ();
If (Str. startswith ("0.") // format of processing. 00989
{
STR = Str. substring (1 );
}
System. Out. println (STR );
}
}
}
/*
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

/* Reference Code
Import java. Io .*;
Import java. util .*;
Import java. Math. bigdecimal;
Public class main {
Public static void main (string [] ARGs ){
Cin = new partition (system. In );
Bigdecimal;
Int P;
String S;
While (CIN. hasnextbigdecimal ()){
A = cin. nextbigdecimal ();
P = cin. nextint ();
S = A. Pow (P). striptrailingzeros (). toplainstring ();
// Striptrailingzeros () Remove unnecessary 0 at the end
// Toplainstring () returns a non-exponential string
System. Out. println (S. startswith ("0 .")? S. substring (1): S );
}
}
}
*/

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.