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. json和pickle的序列化

    PICKle模块:

  2. 【vue】vue中实现标签页

    前言 tab标签页实现很多, 纯css实现, js实现等, 外加一些特殊动画. vue中实现标签页实现 keep-alive标签和is特性 vue-router中嵌套路由 is特性实现(推荐) 优点: ...

  3. Mac 执行 gulp 报错 -bash: gulp: command not found

    在mac系统下安装gulp,之后执行gulp 报如下错误: -bash: gulp: command not found 回溯安装过程发现问题如下 1.执行 npm root: Application ...

  4. 30.IK分词器配置文件讲解以及自定义词库

    主要知识点: 知道IK默认的配置文件信息 自定义词库     一.ik配置文件     ik配置文件地址:es/plugins/ik/config目录     IKAnalyzer.cfg.xml:用 ...

  5. 远程连接Ubuntu的桌面

    参考:http://www.linuxidc.com/Linux/2016-06/132442.htm http://teliute.org/linux/TeUbt/lesson52/lesson52 ...

  6. Pillow 模块~Python图像处理

    什么是验证码? 验证码(CAPTCHA)是“Completely Automated Public Turing test to tell Computers and Humans Apart”(全自 ...

  7. ajax学习----json,前后端交互,ajax

    json <script> var obj = {"name": "xiaopo","age": 18,"gender ...

  8. 浅析gcc、arm-linux-gcc和arm-elf-gcc关系

    浅析gcc.arm-linux-gcc和arm-elf-gcc关系 一.GCC简介 The GNU Compiler Collection,通常简称 GCC,是一套由 GNU 开发的编译器集,为什么是 ...

  9. ERROR: mount point </.alt.rootd3_EISMar14/opt/oracle/product/10.2> is already in use

    在给solaris系统升级的时候,用lu方法遇到下面的错误. -bash-3.2# lumount rootd3_EISMar14 ERROR: mount point </.alt.rootd ...

  10. CF #328div2 D

    这题不难,当时想出来了,可是却写不出来~~ 现在慢慢写回来,也写得好挫~ 可以知道,被攻击的城市必定可以组成一棵树,然后,传送到的点必定也是城市之一.如果出发后回到原点,则需要2E,E是树的边数,则2 ...