ACM_Exponentiation
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的更多相关文章
随机推荐
- Fiddler构造请求
Fiddler工具是一个http协议调试代理工具,它可以帮助程序员测试或调试程序,辅助web开发. Fiddler工具可以发送向服务端发送特定的HTTP请求以及接受服务器回应的请求和数据,是web调试 ...
- cmake更新版本简记
问题描述: 由于需求,要在服务器上安装ANTs(Advanced Normalization Tools).然而最新版的ANTs需要下载源码并用cmake编译, 于是根据https://github. ...
- uva10082 WERTYU (Uva10082)
A common typing error is to place the hands on the keyboard one row to the right of the correct posi ...
- Problem 63
Problem 63 https://projecteuler.net/problem=63 Powerful digit counts The 5-digit number, 16807=75, i ...
- python常用三方库 - openpyxl
目录 python常用三方库 - openpyxl 读取Excel文件 写入Excel文件 python常用三方库 - openpyxl openpyxl是一个第三方库, 可以处理xlsx格式的Exc ...
- 第七节:numpy之矩阵及特殊矩阵的创建
- Python基础-画菱形
方法一 n = int(input('请输入:')) for i in range(1, n, 2): print(('*'*i).center(n)) for i in reversed(range ...
- linux 头文件和库文件的设置
GCC/G++会查找系统默认的include和link的路径,以及自己在编译命令中指定的路径.自己指定的路径就不说了,这里说明一下系统自动搜索的路径. [1]include头文件路径 除了默认的/us ...
- 一个电商项目的Web服务化改造7:Dubbo服务的调用,4个项目
使用dubbo服务的过程,很简单,和之前学习的WebService完全一样,和本地接口调用也基本一致. dubbo和WebService的区别:我认为dubbo就是封装了WebService,然后提供 ...
- hadoop在线退役datanode
退役dn2echo "dn2" >>excludes echo "dn2" >>yarn-excludes sh refresh-nam ...