hdu 1002 A + B Problem II(java)
A + B Problem II
Time运行时间约束:2,000/1,000毫秒(适用于Java等语言)
Memory内存占用限制:65,536/32,768千字节(适用于Java等语言)
Total submissions总提交数量:413,635个
Accepted submissions已通过提交数量:80,168个
Problem Description
She presents such a straightforward issue for you. You are tasked with computing the total of their sum.
Input
The input begins with an integer T, where 1<=T<=20, representing the number of test cases. This is followed by T lines, each containing two positive integers A and B. It is important to note that these integers are very large in value; therefore, they cannot be processed using a 32-bit integer type. Additionally, it can be assumed that the length of each integer will not exceed 1000 characters.
Output
For each test case, please output two lines. The first line should be labeled as "Case #:", where # denotes the test case number. The second line should present an equation in the form "A + B = Sum", where Sum represents the sum of A and B. Please note that there are some spaces within this equation. After processing all equations, output a blank line between every two consecutive test cases.
Sample Input
2 1 2 112233445566778899 998877665544332211
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
练习ACM题目是一种常见的算法训练方式。在编程实现时通常需要特别处理超出普通整型范围的大数值,在这种情况下只能使用数组来模拟运算过程。这一过程往往耗时且复杂。现在是计算机科学与技术专业的二年级学生,在学习Java编程后发现编写一个简单的首行代码——解决一个基础的大数加法问题变得相对容易许多。
import java.math.*;
import java.util.*;
import java.*;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n;
n = scanner.nextInt();
for (int i=1;i<=n;i++){
System.out.println("Case " + i + ":");
BigInteger a,b,c;
a = scanner.nextBigInteger();
b = scanner.nextBigInteger();
c = a.add(b);
System.out.println(a.toString() + " + " + b.toString() + " = " + c.toString());
if(i!=n){
System.out.println();
}
}
}
}
