/**
* 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
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = null;
try {
while ((s = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(s);
BigDecimal a = new BigDecimal(st.nextToken());
int i = Integer.parseInt(st.nextToken());
String s2;
if (i == 0)
//阶乘0时直接输出1
s2 = "1";
else if (i == 1)
//阶乘1时输出原数(不使用科学计数法)
s2 = a.toPlainString();
else
//计算阶乘
s2 = a.pow(i).toPlainString();
if (s2.startsWith("0")) {
//去整数0
s2 = s2.substring(1);
}
while ((s2.endsWith("0") && s2.contains("."))
|| s2.endsWith(".")) {
//去尾数0或无意义的小数点
s2 = s2.substring(0, s2.length() - 1);
}
if (s2.length() == 0) {
//所有操作后若字符串为空,则该数为0
s2 = "0";
}
System.out.println(s2);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
这是一求阶乘的题目,我的想法咧,用BigDecimal把结果求出来先,然后用toPlainString得到完整的值(默认貌似是科学计数法表示的),最后是按题目要求把值按格式输出
分享到:
相关推荐
HDOJ Problem 1001 C++版
2020 CCPC第一题题目!
HDOJ Problem 1001 C++版
杭电ACM第1001题的代码。这个A+B PROBLEM的变形。初学者只要习惯了就好
洛谷题解:P1001-A+B Problem
ITM Problem Determination Guide
NULL 博文链接:https://weitch.iteye.com/blog/1006774
杭电acm第1001题,Sum Problem
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 ) and n is an integer such that 0 输入说明 The input will consist of a set of pairs of...
自己写得大数浮点数幂运算(c++实现),系poj acm 的problem:1001的实现
信息学奥赛一本通(C++版)在线评测系统,答案,1000-1009,前10道题。http://ybt.ssoier.cn:8088/problem_list.php?page=
1001 AB 1003 斐波那契函数 1008 甲/乙 1010 架桥 1011 带我飞到半人马座阿尔法星 1012 有机卷心菜 1037 措施 1075 分配 1094 酒吧 1100 空白 1110 正循环 1152 字数 1157 学习单词 1158 约瑟夫斯问题 1212 八进制二...
2018年-多校培训创造新一轮运行脚本为python create_round.py < round> < problem> 那么您将获得一个名为“ Round ”的文件夹,其中的<problem> cpp文件名为1001.cpp,1002.cpp,... 调用template函数以预处理带有...
1001 1002 1003 1004 1006 1007 专题分类 (一)简单搜索 ID Problem C++ Source 1 HDU 2553 (精简版) 2 HDU 1312 3 POJ 3984 4 POJ 2251 5 POJ 3278 6 POJ 3279 7 ZOJ 1002 8 POJ 1321 9 HDU 1241 (二)树 ID Problem ...
1001 1002 1003 1004 1006 1007 专题分类 (一)简单搜索 ID Problem C++ Source 1 HDU 2553 (精简版) 2 HDU 1312 3 POJ 3984 4 POJ 2251 5 POJ 3278 6 POJ 3279 7 ZOJ 1002 8 POJ 1321 9 HDU 1241 (二)树 ID Problem ...
4. 1001 计算两点间的距离 这道题目考察了编程语言的数学计算能力,要求编写程序来实现两点间的距离计算。这类题目考察了编程语言的数学函数和算法实现能力。 知识点: * 数学函数(sin、cos、sqrt 等) * 坐标系...
Problem Python Go C++ Rust 中文题目 中文题解 0001 [链接] 501 ~ 1000 # Problem Python Go C++ Rust 中文题目 中文题解 0501 [Python] [Go] [C++] [Rust] [链接] 1001 ~ ∞ # Problem Python Go C++ Rust 中文...
ECNU 1-100 部分AC程序 problem list : 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1011 1012 1013 1014 1015 1017 1018 1019 1020 1023 1026 1027 1029 1030 1031 1036 1037 1038 1040 ...
- Changes to correct a BurnInTest crash problem on some systems. When the disk and standard RAM tests are run for many hours, BurnInTest may have disappeared with no error message. Release 5.3 ...
│ Objective-C.Recipes.A.Problem-Solution.Approach,.Matthew.Campbell,.Apress,.2012-.epub │ Professional.C.Plus.Plus,.Marc.Gregoire,.Nicholas.A..Solter,.Scott.J..Kleper,.2ed,.Wiley,.2011-.epub │ ...