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. Linux常用命令(简单的常用)

      1. 文件和目录 cd /home 进入 '/ home' 目录' cd .. 返回上一级目录 cd ../.. 返回上两级目录 cd 进入个人的主目录 cd ~user1 进入个人的主目录 cd ...

  2. 【转载】IDEA:XML配置提示URI is not registered

    在idea开发中,遇到xml提示URI is not registered....其实是idea找不到约束文件,下面讲解一下如何解决这一个问题吧. 现的问题是,xml文件右边有提示,提示内容为:URI ...

  3. uva 1586 Molar mass(Uva-1586)

    这题做的相当的复杂...之前做的现在应该能简单一点了写的. 我的代码: #include <bits/stdc++.h> using namespace std; main() { int ...

  4. 35.分组聚合操作—bucket+metric

    主要知识点: bucket+metric 计算分种颜色的电视的平均价格     语法: GET /tvs/sales/_search { "size" : 0, "agg ...

  5. Django-搭建win7虚拟环境-virtualenv

    为什么要配置Django虚拟环境? 例如:在开发Python Django的时候,系统安装的Python3只有一个版本:3.6.所有第三方的包都会被pip安装到Python3的site-package ...

  6. Redis 原子操作INCR

    The content below come from http://try.redis.io/ There is something special about INCR. Why do we pr ...

  7. Java基础学习总结(42)——Log4j 2使用教程

    1. 去官方下载log4j 2,导入jar包,基本上你只需要导入下面两个jar包就可以了(xx是乱七八糟的版本号): log4j-core-xx.jar log4j-api-xx.jar 2. 导入到 ...

  8. 清北学堂模拟赛d7t3 天上掉馅饼

    题目描述小 G 进入了一个神奇的世界,在这个世界,天上会掉下一些馅饼.今天,天上会随机掉下 k 个馅饼.每次天上掉下馅饼,小 G 可以选择吃或者不吃(必须在下一个馅饼掉下来之前作出选择,并且现在决定不 ...

  9. 这书真的不错--Spring MVC Beginner's Guide

    五百多页,我干到三百多页了. 每个知识点都有说明,操作,解释. 学SPRING MVC,有它就够了. 遗憾的是,这个PDF的文档格式太稀松啦,且,无中文版~~~ 我都想作汉化翻译工作了...算了,忍住 ...

  10. CODEVS——T 1049 棋盘染色

    http://codevs.cn/problem/1049/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descr ...