杭电OJ1002
先上代码
package hdu1;
import java.math.BigInteger;
import java.util.Scanner;
public class AaddB问题II {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i=1;
while (in.hasNextInt()) {
int count=in.nextInt();
while(count-->0){
if(i!=1)
System.out.println();
BigInteger a=in.nextBigInteger();
BigInteger b=in.nextBigInteger();
System.out.println("Case "+i+":");
System.out.println(a+" + "+b+" = "+a.add(b));
i++;
}
}
}
}
思路:看题目中要求整数非常大,首先采用的是long类型。
坑坑
这题的数可以是非常大,所以弃long用BigInteger;对于case后数字如何让其实现逐渐加1,这里直接用了一个i++;输出格式这块,加了if(i!=1) System.out.println();
除了case1:,后面的输出都要加上空白行,注意这里是不能用if(count!=1) System.out.println();
的,否则在case1:前面也会有一行空白行的。