AcWing 791. 高精度加法
原题链接
简单
作者:
Luo_4
,
2021-03-18 22:38:02
,
所有人可见
,
阅读 312
字符串
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scann = new Scanner(System.in);
String s1 = scann.nextLine();
String s2 = scann.nextLine();
int idx1 = s1.length()-1;
int idx2 = s2.length()-1;
int c = 0;
StringBuilder sb = new StringBuilder();
while(idx1 >= 0 || idx2 >=0 || c > 0){
int sum = 0;
if(idx1>=0){
sum += Integer.parseInt(String.valueOf(s1.charAt(idx1)));
idx1--;
}
if(idx2>=0){
sum += Integer.parseInt(String.valueOf(s2.charAt(idx2)));
idx2--;
}
sum += c;
c = sum/10;
sb.insert(0,sum%10);
}
System.out.println(sb.toString());
}
}