HDU1753 Ming A + B (big numbers together) (the Java explanations)

Ming A + B

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16499    Accepted Submission(s): 6082

Problem Description

Saying that after a long month, Xiao Ming has grown a lot, so he changed a name called "Ming."
At this time he is not only do that within 100 addition that "Bob", and now he'll even positive addition to any fractional length.
Now, you give two positive decimal A and B, your task is to calculate the value representative of the Ming of A + B.

Input

This topic contains multiple sets of test data, the processing to the end of the file.
Each set of test data is included in the length of a line which is not greater than two decimal positive and B. A 400

Output

Please output value A + B in a row inside, output a simplest form. See detailed requirements Sample Output.

Sample Input

1.1 2.9 1.1111111111 2.3444323343 1 1.1

Sample Output

4 3.4555434454 2.1

 

 

code show as below:

import java.math.BigDecimal;
import java.math.*;
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
 Scanner scan=new Scanner(System.in);
 BigDecimal a=new BigDecimal("0");
 BigDecimal b=new BigDecimal("0");
 while(scan.hasNext()){
 a=scan.nextBigDecimal();
 b=scan.nextBigDecimal();
 System.out.println(a.add(b).stripTrailingZeros().toPlainString());
   }
  }
}

Guess you like

Origin www.cnblogs.com/jianqiao123/p/11202551.html