Exponentiation

Time Limit: 2000/1000ms (Java/Others)

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
解题思路:计算r^n,要求:①如果整数部分为0,去掉整数部分;②去掉结果尾部的所有0,java水过!
AC代码:
 import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
BigDecimal bd = new BigDecimal(scan.next());
BigDecimal result = bd.pow(scan.nextInt());
//stripTrailingZeros()的使用方法:返回数值上等于此小数,但从该表示形式移除所有尾部零的 BigDecimal。
//toPlainString()的使用方法:返回不带指数字段的此 BigDecimal的字符串表示形式。
String obj = result.stripTrailingZeros().toPlainString();
//startsWith(String prefix)的使用方法:测试此字符串是否以指定的前缀开始。这里表示如果整数部分为0,就截取除下标为0的子串
if(obj.startsWith("0"))obj=obj.substring(1);
System.out.println(obj);
}
}
}

ACM_Exponentiation的更多相关文章

随机推荐

  1. 【转载】文件上传Expected MultipartHttpServletRequest: is a MultipartResolver错误解决

    引入包commons-fileupload-*.jar,版本号可以根据项目情况调整: 在spring mvc配置文件中增加配置,文件大小限制可根据项目情况调整: <!-- 上传文件拦截,设置最大 ...

  2. 集成学习_Bagging 和随机森林(rf)

       集成学习方式总共有3种:bagging-(RF).boosting-(GBDT/Adaboost/XGBOOST).stacking      下面将对Bagging 进行介绍:(如下图所示) ...

  3. 经典的GDB调试命令,包括查看变量,查看内存

    经典的GDB调试命令,包括查看变量,查看内存 在你调试程序时,当程序被停住时,你可以使用print命令(简写命令为p),或是同义命令inspect来查看当前程序的运行数据.print命令的格式是: p ...

  4. Neo4j图数据库从入门到精通

    目录 第一章:介绍 Neo4j是什么 Neo4j的特点 Neo4j的优点 第二章:安装 1.环境 2.下载 3.开启远程访问 4.启动 第三章:CQL 1.CQL简介 2.Neo4j CQL命令/条款 ...

  5. js for 循环 添加tr td 算法

    StringBuffer sb=new StringBuffer(); int n = 5; sb.append("<tr>"); List<MenuBean&g ...

  6. css3部分注意事项

    CSS 选择符有哪些?哪些属性可以继承?优先级算法如何计算? CSS3新增伪类有那些? 1.选择器 id选择器( # myid) 类选择器(.myclassname) 标签选择器(div, h1, p ...

  7. 几校联考——day1题解

    T1 约数的个数(好像不可提交) 如果一个整数a能够整除整数b,那么a叫做b的约数.现在有N(1 <= N <= 100,000)个整数,对于其中的每一个数,请找出它在其余N - 1个整数 ...

  8. uva253 Cube painting(UVA - 253)

    题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相 ...

  9. JDK5-8特性归纳

    jdk5新特性1.自动装箱和拆箱2.枚举3.静态导入4.可变参数5.內省   是Java语言对Bean类属性.事件的一种缺省处理方法.例如类A中有属性那么,那我们可以通过getName,setName ...

  10. 【codeforces 509C】Sums of Digits

    [题目链接]:http://codeforces.com/contest/509/problem/C [题意] 给你一个数组b[i] 要求一个严格升序的数组a[i]; 使得a[i]是b[i]各个位上的 ...