hdu1753 Daming A+B

Daming A+B

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


Problem Description
In other words, after more than a long month, Xiao Ming has grown a lot, so he changed his name to "Da Ming".
At this time, he is no longer the "Xiao Ming" who can only add up to 100, and now he can even add positive decimals of any length.

Now, given two positive decimals A and B, your task is to calculate the value of A+B on behalf of Daming.
 

Input
This question contains multiple sets of test data, please process until the end of the file.
Each set of test data contains two positive decimals A and B whose length is not greater than 400 in one line.
 

Output
Please output the value of A+B in one line, please output the simplest form. See Sample Output for detailed requirements.
 

Sample Input
 
  
1.1 2.9 1.1111111111 2.3444323343 1 1.1
 

Sample Output
 
  
4 3.4555434454 2.1
 

Author
linle
 

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325746459&siteId=291194637