【大数问题】 HDOJ 1047 Integer Inquiry

大数加法~~~

import java.util.Scanner;
import java.math.BigInteger;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int n;
		BigInteger a,  ans, b;
		b = BigInteger.valueOf(0);
		n = scanner.nextInt();
		for(int i = 1; i <= n; i++) {
			ans = BigInteger.ZERO;
			while(scanner.hasNext()) {
				a = scanner.nextBigInteger();
				if(a.compareTo(b) == 0) break;
				else ans = ans.add(a);
			}
			System.out.println(ans);
			if(i != n) System.out.println();
		}
	}
}




你可能感兴趣的:(HDU)