Hdu 1002 (Java), hdu1002 java

Source: Internet
Author: User

Hdu 1002 (Java), hdu1002 java
A + B Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 230395    Accepted Submission(s): 44208


Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
InputThe first line of the input contains an integer T (1 <= T <= 20) which means the number of test cases. then T lines follow, each line consists of two positive integers, A and B. notice that the integers are very large, that means you shoshould not process them by using 32-bit integer. you may assume the length of each integer will not exceed 1000. 
OutputFor each test case, you should output two lines. the first line is "Case #:", # means the number of the test case. the second line is the an equation "A + B = Sum", Sum means the result of A + B. note there are some spaces int the equation. output a blank line between two test cases. 
Sample Input2 1 2 112233445566778899 998877665544332211 
Sample OutputCase 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110 


Link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1002


It is A simple A + B, so you only need to pay attention to the last set of data before there is no extra blank lines. It is troublesome to use c/c ++, it's easy to use java, so ~, C code will not be pasted.



1 import java. util. *; 2 2 import java. math. *; 3 3 public class Main {4 4 public static void main (String [] args) {5 5 int T; 6 6 BigDecimal a, B, c; // define two large-number variables, a, B 7 7 cin = new Numeric (System. in); 8 8 T = cin. nextInt (); 9 9 for (int I = 1; I <= T; I ++) {10 10 a = cin. nextBigDecimal (); 11 11 B = cin. nextBigDecimal (); 12 12 // c =. add (B); // The addition of java is different from that of c/c ++. The four arithmetic operations must be written in this form 13 13 System. out. println ("Cas E "+ I +": "); 14 14 System. out. println (a + "+" + B + "=" + (. add (B); 15 15 if (I! = T) // There are no extra blank rows after the last group of data. 16 16 System. out. println (); 17 17} 18 18 19 19} 20 20}View Code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.