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.


 

最新文章

  1. myeclipse连接数据库sql server
  2. c#多态性
  3. bzoj2179: FFT快速傅立叶
  4. MySQL中EXPLAIN的解释
  5. ORACLE10G工作原理
  6. Linux系统编程@终端IO
  7. 【网络流#5】UVA 11082 最大流
  8. Application值传递。
  9. IOS应用程序生命周期详解
  10. linux面试
  11. Objective-C中关于请求返回NSData数据解析成NSDictionary或NSArray的方法
  12. PHP中单引号、双引号和转义字符
  13. django-rest-framework快速入门
  14. 01. SELECT显示和PRINT打印超长的字符
  15. C++学习-6
  16. MVCAPi Httpclient
  17. linux部署二:网卡配置和Yum源的替换
  18. Pyhton之subprocess模块和configparser模块
  19. 如何进行SQL排序
  20. .NET中使用FastReport实现打印功能

热门文章

  1. C#Linq技术中SelectMany(...)函数的内部实现的伪代码
  2. ArcGIS API for JavaScript 4.2学习笔记[12] View的弹窗(Popup)
  3. bzoj 3999: [TJOI2015]旅游
  4. php-递归创建级联目录
  5. [知了堂学习笔记]_用JS制作《飞机大作战》游戏_第3讲(玩家发射子弹)
  6. 在html中使用js
  7. shiro中 UnknownAccountException
  8. JavaScript的DOM编程--03--读写属性节点
  9. 前端学习_04_font-awesome字体图标
  10. 《UNP》学习之TCP状态转换