Powerful java features of HDU 1002 Big Data Operations

Source: Internet
Author: User
A + B Problem II

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


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 Input

21 2112233445566778899 998877665544332211
 


Sample Output

Case 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110

For the powerful java operations, I still remember that I had read the code of this question for a whole day when I learned c ++ large number addition. I want to convert it into an array for processing. Today, one year later, I learned how to add large numbers to solve this problem.

Post code

Import java. util. *; import java. math. *; import java. io. *; public class Main // note that the class name must use the uppercase Main {public static void main (String [] args) {Variable cin = new variable (new BufferedInputStream (System. in); BigInteger a, B, c; // defines three big integers: int ji, num = 0; ji = cin. nextInt (); // read judgment condition while (ji> = 1) {ji --; num ++; a = cin. nextBigInteger (); // read the big integer B = cin. nextBigInteger (); c =. add (B); System. out. println ("Case" + num +" : "); // Output result System. out. println (a +" + "+ B +" = "+ c); if (ji! = 0) System. out. println ("");}}}

Related Article

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.