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 ("");}}}