POJ1001
来源:互联网 发布:热云数据地址 编辑:程序博客网 时间:2024/04/30 00:51
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many 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.
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 should 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
toString 和 toPlainString区别对于 BigDecimal b ; (b=(0.4321)^ 20)String s = b.toPlainString() ;System.out.println(s) ; 输出为:0.00000005148554641076956121994511276767154838481760200726351203835429763013462401若String s = b.toString() ;输出为:5.148554641076956121994511276767154838481760200726351203835429763013462401E-8
import java.math.BigDecimal;import java.util.Scanner;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner sc = new Scanner(System.in);while(sc.hasNext()){BigDecimal r = sc.nextBigDecimal();//不可变的、任意精度的有符号十进制数。int n = sc.nextInt();BigDecimal result = r.pow(n);//double result = Math.pow(r, n);String resultString = result.stripTrailingZeros().toPlainString();//返回数值上等于此小数,但从该表示形式移除所有尾部零的 BigDecimal。if(resultString.startsWith("0.")){resultString = resultString.substring(1);}System.out.println(resultString);}}}
0 0
- POJ1001
- poj1001
- poj1001
- POJ1001
- POJ1001
- poj1001
- POJ1001
- poj1001
- POJ1001
- POJ1001
- poj1001
- POJ1001
- POJ1001
- poj1001
- POJ1001
- POJ1001
- POJ1001
- poj1001
- 因修改/etc/sudoers权限导致sudo和su不能使用的解决方法
- Spring资源访问机制
- 用C++编写16进制字符数组转ASCII码字符数组的函数
- IBM——TSM数据存储与备份的管理
- 数字电路(一)
- POJ1001
- LA4642 Malfatti Circles Malfatti 定理 Tokyo 2009
- 如何在VS中调用CLAPACK
- strncpy的实现
- 哈希表
- 关于 oracle 12c
- JAVA练习(URL)
- 状态与信心(2013.10.13)
- ubuntu下sudo命令不再输入密码