`
贝壳水母
  • 浏览: 149201 次
  • 性别: Icon_minigender_1
  • 来自: 广州中低收入人群
社区版块
存档分类
最新评论

Problem1001

    博客分类:
  • POJ
阅读更多


/**
 * 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得到完整的值(默认貌似是科学计数法表示的),最后是按题目要求把值按格式输出
分享到:
评论

相关推荐

    Problem 1001

    HDOJ Problem 1001 C++版

    Problem - 1001.pdf

    这个问题是2020年CCPC(中国大学生程序设计竞赛)的第一题,题目涉及的是二维平面中的矩形覆盖问题,并要求计算出黑色区域周长的变化。编程语言要求使用C++。 题目描述: 在这个问题中,想象一个婴儿Volcano正在用...

    Problem 1002

    HDOJ Problem 1001 C++版

    ZOJ1001 A + B Problem

    【ZOJ1001 A + B Problem】是在线判题系统ZOJ(Zhejiang Online Judge)上的一道编程题目。这道题目通常作为入门级别的算法问题,目的是让初学者熟悉在线判题系统的提交流程以及基本的编程概念。题目要求编写一个...

    CSUOJ,264个问题的正确代码

    在Problem1001中,使用了Java语言来实现一个简单的程序。该程序接收用户输入的整数n,并输出n行星号。这段代码展示了Java的基本语法,包括类定义、方法声明、条件语句等。关键代码如下: ```java import java.util....

    acm比赛试题

    Problem 1001 本题的标题是“Word Reversal”,它是一道字符串处理题目,要求将输入的单词逆序输出。该题目考察了字符串处理和算法设计的知识点,需要使用字符串逆序算法来解决问题。 知识点: 1. 字符串处理 2. ...

    杭电ACM-HDUOJ 1001 SUM problem

    ### 杭电ACM-HDUOJ 1001 SUM problem #### 题目背景与概述 杭电ACM-HDUOJ 1001 SUM problem 是一道非常基础且适合编程初学者练习的题目。根据描述,这道题目是“A+B PROBLEM”的一种变形,主要考察的是循环结构和...

    分类练习北大acm题库

    "半个月"这个文件名看起来不太常规,可能是文件名缺失或者误写,通常在题库中会以更具体的名字来标识每个题目,如"Problem1001.html"或"SortingAlgorithms.docx"等,但在这里可能表示的是一个时间段,比如这是一段...

    洛谷题解:P1001-A+B Problem

    洛谷题解:P1001-A+B Problem主要涉及到知识点包括C++程序设计基础、程序输入输出操作、C++标准库的使用、位运算和C++编译预处理指令。 1. C++程序设计基础: - C++是编译型语言,需要编译成机器语言后才能运行。 ...

    P1001 A+B Problem.c

    洛谷网题目 C语言源码 代码

    杭电acm1001

    杭电acm第1001题,Sum Problem

    POJ1001-Precision power

    【标题】"POJ1001-Precision power"是一个在线编程题目,源自北京大学的POJ(Problem Set of Peking University)平台。该题目主要考察的是算法设计与精度控制方面的知识,尤其是涉及到浮点数计算时的精度问题。 ...

    poj1001高精度乘法

    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++实现)

    自己写得大数浮点数幂运算(c++实现),系poj acm 的problem:1001的实现

    Acm试题及答案29页试题集合全英文44道题目

    1001 Sum Problem - **知识点**:简单的加法运算。 - **背景介绍**:这是一道非常基础的数学题目,要求学生能够熟练掌握整数加法的基本操作,并能正确输出结果。 - **实现方法**: - 输入两个整数 `a` 和 `b`。 -...

    杭电题目acm答案

    - **Examples**: Calculating the sum of a sequence of numbers in `1001 Sum Problem` and sorting ASCII codes in `2000 ASCII Code Sorting`. - **Debugging and Testing**: Ensuring that programs run ...

    2021届电信科协第二周Task.md

    - [P1001](https://www.luogu.com.cn/problem/P1001) - [P1427](https://www.luogu.com.cn/problem/P1427) 通过以上知识点的学习,学员们不仅能够掌握C语言的基础语法,还能加深对控制流、数据结构和算法的理解,为...

    北大ACM题目分类

    2. **题目ID:** [1001](http://acm.pku.edu.cn/JudgeOnline/problem?id=1001) - **题目类型:** 高精度运算 - **知识点:** 大整数运算处理 - **解析:** 本题涉及高精度运算,即大整数的乘除法。题目中还需要处理...

    杭电的答案

    根据给定文件的信息,我们可以总结出杭电ACM竞赛中的三个问题:1000-A+B Problem、1001-Sum Problem 和1002-A+B Problem II 的相关知识点。 ### 杭电ACM 1000 - A+B Problem **题目描述**: 计算两个整数 A 和 B ...

Global site tag (gtag.js) - Google Analytics