首页 > 其他 > 详细

A + B Problem II

时间:2017-12-13 16:09:49      阅读:280      评论:0      收藏:0      [点我收藏+]
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
 
Input
The 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 should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
 
Output
For 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
2 1 2 112233445566778899 998877665544332211
 
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
 
AC代码:
 1 import java.math.BigDecimal;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5 
 6     public static void main(String[] args) {
 7         Scanner reader = new Scanner(System.in);
 8         int nTotal = reader.nextInt();   //nTotal为哪种情况
 9         for(int nCount = 0; nCount < nTotal; nCount++){
10             BigDecimal num1 = reader.nextBigDecimal();
11             BigDecimal num2 = reader.nextBigDecimal();
12             StringBuffer sbTemp = new StringBuffer("Case ");
13             sbTemp.append(nCount+1);
14             sbTemp.append(":\r\n");  //JAVA中的\r\n才是对应的回车换行
15             sbTemp.append(num1.toString());
16             sbTemp.append(" + ");
17             sbTemp.append(num2.toString());
18             sbTemp.append(" = ");
19             sbTemp.append(num1.add(num2).toString());
20             System.out.println(sbTemp.toString());
21             if(nCount != nTotal-1)
22                 System.out.println();
23         }
24     }
25 }

 

A + B Problem II

原文:http://www.cnblogs.com/ixummer/p/8032961.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!