题解 | #高精度整数加法#
高精度整数加法
http://www.nowcoder.com/practice/49e772ab08994a96980f9618892e55b6
增加了过滤非数字部分
import java.util.Scanner; import java.math.BigInteger;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
String str1 = sc.nextLine().replaceAll("[^0-9]","");//把所有非0-9的字符都去掉
String str2 = sc.nextLine().replaceAll("[^0-9]","");
BigInteger a = new BigInteger(str1);
BigInteger b = new BigInteger(str2);
System.out.println(a.add(b));
}
}
}