HDOJ 1753 大明A+B(大数~)

Problem Description
话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。
这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。

现在,给你两个正的小数A和B,你的任务是代表大明计算出A+B的值。

Input
本题目包含多组测试数据,请处理到文件结束。
每一组测试数据在一行里面包含两个长度不大于400的正小数A和B。

Output
请在一行里面输出输出A+B的值,请输出最简形式。详细要求请见Sample Output。

Sample Input
1.1 2.9
1.1111111111 2.3444323343
1 1.1

Sample Output
4
3.4555434454
2.1

Java大数~~~

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            BigDecimal a = sc.nextBigDecimal();
            BigDecimal b = sc.nextBigDecimal();

            a = a.add(b);
            a = a.stripTrailingZeros();
            //返回数值上等于此小数,但从该表示形式移除所有尾部零的 BigDecimal。
            System.out.println(a.toPlainString());
            //a.toPlainString()返回不带指数字段的此 BigDecimal 的字符串表示形式。

        }

    }

}
时间: 2024-10-22 04:55:14

HDOJ 1753 大明A+B(大数~)的相关文章

HDOJ 1018 Big Number(大数位数公式)

Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of

HDOJ 1753

点击打开链接 解题思路:我们开两个数组,数组的前500位存储整数部分,后面500位存储小数部分,开个sum数组求和即可,注意一下小数点的进位 代码: #include<iostream> #include<cstring> #include<cstdio> using namespace std; int s1[1000],s2[1000],sum[1000]; string str1,str2; void copy() { int i , j; int l1 = st

HDOJ 1013题Digital Roots 大数,9余数定理

Problem Description The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits a

【JAVA大数训练】大明A+B

大明A+B Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7440    Accepted Submission(s): 2622 Problem Description 话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫"大明". 这时他已经不是那个只会做100以内加法的那个"小明"了

HDOJ/HDU 1865 1sting(斐波拉契+大数~)

Problem Description You will be given a string which only contains '1'; You can merge two adjacent '1' to be '2', or leave the '1' there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, you

HDOJ 1042 N!(大数阶乘JAVA)

Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process to the end of file. Output For each N, output N! in one line. Sample Input 1 2 3 Sample Output 1 2 6 JAVA 大数轻松AC! import java.math.Bi

HDOJ/HDU 5686 Problem B(斐波拉契+大数~)

Problem Description 度熊面前有一个全是由1构成的字符串,被称为全1序列.你可以合并任意相邻的两个1,从而形成一个新的序列.对于给定的一个全1序列,请计算根据以上方法,可以构成多少种不同的序列. Input 这里包括多组测试数据,每组测试数据包含一个正整数N,代表全1序列的长度. 1≤N≤200 Output 对于每组测试数据,输出一个整数,代表由题目中所给定的全1序列所能形成的新序列的数量. Sample Input 1 3 5 Sample Output 1 3 8 Hin

HDOJ/HDU 1250 Hat&amp;#39;s Fibonacci(大数~斐波拉契)

Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your task is to take

HDOJ/HDU 1297 Children’s Queue(推导~大数)

Problem Description There are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one