本文主要是介绍POJ 题目1001 ,hdu1753 (大数,Java简单题),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://poj.org/problem?id=1001
题目大意: 求R^n , 输出 : 前面的0不输出,后面的零不输出
stripTrailingZeros();//末尾除零
toPlainString(); //返回不带指数字段的此 BigDecimal 的字符串表示形式
package com.hdu;
import java.math.BigDecimal;
import java.util.Scanner;
public class POJ1001 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
BigDecimal r = cin.nextBigDecimal();
int n = cin.nextInt();
BigDecimal ans = r.pow(n).stripTrailingZeros();//除去后面多余的0
System.out.println(ans.toPlainString().replaceAll("^0", ""));
}
}
}
/*
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
*/
http://acm.hdu.edu.cn/showproblem.php?pid=1753
最后输出要加 toPlainString(); 否则WA
package com.hdu;
import java.math.BigDecimal;
import java.util.Scanner;
public class hdu1753 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
BigDecimal a = cin.nextBigDecimal();
BigDecimal b = cin.nextBigDecimal();
a = a.add(b);
System.out.println(a.stripTrailingZeros().toPlainString());
}
}
}
/*
Sample Input
1.1 2.9
1.1111111111 2.3444323343
1 1.1
Sample Output
4
3.4555434454
2.1
* */
这篇关于POJ 题目1001 ,hdu1753 (大数,Java简单题)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!