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. CentOS下修改root用户名

    修改root登录用户名减少Linux云主机“被暴力破解”警告,登录云主机的时候就先显示登录失败多少次.其是公网有人在扫用弱密码破解登录. 所谓暴力破解,就是用“用户名“+”密码”穷举的方式进行远程登录 ...

  2. Git学习总结四(删除)

    一般情况下,你通常直接在文件管理器中把没用的文件删了,或者用rm命令删了: $ rm test.txt 这个时候,Git知道你删除了文件,因此,工作区和版本库就不一致了,git status命令会立刻 ...

  3. js的基础运用

    总结: 1.定义:分为隐式定义和显式定义可以先定义后赋值. 2.+:当两边都是数值则运行加法运算,若一遍是字符型则进行拼接. 3.数值变字符:数值变量.toString()方法. 字符变数值:通过加一 ...

  4. flutter 环境搭建

    环境: ladder什么的是必不可少的 win10 + Idea 2019.1.13 + Genymotion 2.12 基本可以在模拟器中运行项目,还有些许小问题,但是可以看到效果了 基本流程 下载 ...

  5. 14.multi_match+most-fields策略

    主要知识点 most-fields策略的用法 most-fields策略和best-fields的比较         best-fields策略:将某一个field匹配尽可能多的关键词的doc优先返 ...

  6. 在 ServiceModel 客户端配置部分中,找不到引用协定“XXX”的默认终结点元素

    一.问题 在调用远程web services接口时出现了以下问题: 二.可能的原因和解决方法 网站根目录里的web.config文件缺少了相应的配置信息 <?xml version=" ...

  7. [网络收集]20190528华为数通网络工程师认证HCIA-VRP的操作指导思维导图

    >> >0 VRP基础 >1 命令行基础 >2 文件系统基础 >3 VRP系统管理

  8. kafka监控工具kafka-manager

    1.几个kafka监控工具 Kafka Web Console:监控功能较为全面,可以预览消息,监控Offset.Lag等信息,但存在bug,不建议在生产环境中使用. Kafka Manager:偏向 ...

  9. hdu 4081 最小生成树变形

    /*关于最小生成树的等效边,就是讲两个相同的集合连接在一起 先建立一个任意最小生成树,这条边分开的两个子树的节点最大的一个和为A,sum为最小生成树的权值和,B为sum-当前边的权值 不断枚举最小生成 ...

  10. hibernate分表保存日志

    @Service("accessLogService")@Transactionalpublic class LogMessageServiceImpl extends BaseD ...