http://acm.hdu.edu.cn/showproblem.php?pid=1063

Exponentiation

Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8076    Accepted Submission(s): 2279

Problem 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. 

 
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 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
 import java.math.BigDecimal;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while(s.hasNext()){
BigDecimal b = s.nextBigDecimal();
BigDecimal ans = BigDecimal.valueOf(1);
int n = s.nextInt();
while(n-- > 0)
ans = ans.multiply(b);
String string = ans.stripTrailingZeros().toPlainString().toString();
if(string.startsWith("0."))
string = string.substring(1);
System.out.println(string);
}
s.close();
}
}
1、stripTrailingZeros() ,返回类型为BigDecimal的小于此数的但除去尾部的0的数值。
2、toPlainString(),返回BigDecimal类型的String类型字符串。
3、startsWith(),确定此实例的开头是否与指定的字符串匹配。
4、substring(),返回一个新的字符串,它是此字符串的一个子字符串。该子字符串始于指定索引处的字符,一直到此字符串末尾。

大家都知道JAVA的类一般都要带toString这个方法的,BigDecimal则有toString,toPlainString和toEngineeringString三种表示成字符串的方法,


下面是这三种方法各自的特点:


toString: using scientific notation if an exponent is needed;


toEngineeringString:using engineering notation if an exponent is needed.


toPlainString:without an exponent field.


 

Exponentiation(java 大实数)的更多相关文章

  1. HDU ACM 1063 Exponentiation 大实数乘方

    分析:大实数乘方计算. #include<iostream> #include<string> using namespace std; struct BigReal //高精 ...

  2. java高精度实数和小数

    java 高精度实数和小数 String s = "1231222222222222222222222222222222222222222222222222222222"; Big ...

  3. [原创]java WEB学习笔记81:Hibernate学习之路--- 对象关系映射文件(.hbm.xml):hibernate-mapping 节点,class节点,id节点(主键生成策略),property节点,在hibernate 中 java类型 与sql类型之间的对应关系,Java 时间和日期类型的映射,Java 大对象类型 的 映射 (了解),映射组成关系

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  4. JAVA 大数据内存耗用测试

    JAVA 大数据内存耗用测试import java.lang.management.ManagementFactory;import java.lang.management.MemoryMXBean ...

  5. Java大数据应用领域及就业方向

    最难毕业季,2017高校毕业生达到795万,许多学生面临着毕业即失业的尴尬.面对着与日俱增的竞争形势和就业压力,很多毕业生选择去知了堂学习社区镀金,以提高自己的就业竞争力,其中Java大数据是学生选择 ...

  6. 为什么Java大数据是最火爆的编程语言?

    未来10年将是大数据,人工智能爆发的时代,到时将会有大量的企业需要借助大数据,而Java最大的优势就是它在大数据领域的地位,目前很多的大数据架构都是通过Java来完成的. 在这个Android.iOS ...

  7. Java大数据人才应用领域广,就业薪酬高

    互联网创造了大数据应用的规模化环境,大数据应用成功的案例大都是在互联网上发生的, 互联网业务提供了数据,互联网企业开发了处理软件,互联网企业的创新带来了大数据应用 的活跃,没有互联网便没有今天的大数据 ...

  8. Java:大文件拆分工具

    java大文件拆分工具(过滤掉表头) import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File ...

  9. 如何学好Java大数据并快速提升

    Java作为一种最流行的,最热门的编程语言,可以说它无处不在,目前全球有着数十亿的设备正在运行着Java,很多服务器程序都是用Java编写,用以处理每天超过数以千万的数据.无论是手机软件.手机Java ...

随机推荐

  1. C:数据结构与算法之单链表

    单链表相对于顺序表比较难理解,但是比较实用,单链表的插入,删除不需要移动数据元素,只需要一个指针来寻找所需要的元素,还有一个大优点就是不浪费空间,当你想要增加一个结点可以申请(malloc())一个结 ...

  2. Python模块之pickle(列表,字典等复杂数据类型与二进制文件的转化)

    1.pickle模块简介 The pickle module implements binary protocols for serializing and de-serializing a Pyth ...

  3. locate 命令详解

    locate :http://www.cnblogs.com/peida/archive/2012/11/12/2765750.html 作用:locate命令可以在搜寻数据库时快速找到档案,数据库由 ...

  4. 1.QT开发第一个程序

    Ubuntu16.04安装QT5.8.0:http://www.cnblogs.com/dotnetcrazy/p/6725945.html QT5.8支持中文输入法(附带老版本的解决+不理想的情况解 ...

  5. HTTPS从认识到线上实战全记录

    前言 关于HTTPS,基本上你想知道的都在这里了.本文原标题<HTTPS原理与实践>,下图是本文配套PPT的目录截图: [TOC] 原理篇 认识HTTPS 先说一下,本文可能有些地方由于描 ...

  6. java RTTI笔记 之Class学习笔记(摘自java编程思想)

    1.java 使用Class对象来执行其RTTI.java 中每个类在编译后都会对应产生一个Class对象(更恰当地说是被保存在一个同名的.class文件中),甚至void和基本类型也都对应一个cla ...

  7. 巧用php中的array_filter()函数去掉多维空值

    一直一维array_filter() 函数只能去除一维数组,其实这个函数也能去除多维数组: $arr =[ '0'=>array(), '1'=>'false', '2'=>'tes ...

  8. HTML5发布的意义

    解决文档结构混乱 以前的文档结构过度依赖div,HTML5推出了多种语义化标签,使得文档更利于阅读器等理解,更利于SEO优化. 解决浏览器之间的兼容性问题 市场上浏览器种类繁多,每个浏览器厂商都在做自 ...

  9. 房上的猫:HTML5基础

    一.W3C标准 1)W3C标准不是某一个标准,而是一系列的标准的集合,一个网页主要由三部分组成,即结构(Structure),表现(Presentation)和行为(Behavior) 2)不很严谨的 ...

  10. IDA Pro反编译代码类型转换参考

    /* This file contains definitions used by the Hex-Rays decompiler output. It has type definitions an ...