就是求Case组样例,未知个数的和,还是简单的大数相加的问题,值得注意的就是格式的问题,JAVA用hasNext()判断是否还有下一个输入。
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin = new Scanner ( System.in );
BigInteger ans = BigInteger.valueOf( 0 );
BigInteger num;
int Case;
Case = cin.nextInt ( );
while ( cin.hasNext() ) {
num = cin.nextBigInteger ( );
if ( num.equals( BigInteger.valueOf( 0 ) ) ) {
System.out.println ( ans );
Case--;
ans = BigInteger.valueOf( 0 );
if ( Case != 0 ) System.out.println ( );
continue;
}
ans = ans.add ( num );
}
}
}