import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
String s1=scanner.next();
String s2=scanner.next();
System.out.println(calculate(s1,s2));
}
public static String calculate(String s1,String s2){
int a;
int b;
int i=s1.length()-1;
int j=s2.length()-1;
int temp=0;
int add=0;
StringBuilder sb=new StringBuilder();
while(i>=0&&j>=0){
a=s1.charAt(i)-'0';
b=s2.charAt(j)-'0';
temp=a+b+add;
add=temp/10;
temp=temp%10;
sb.insert(0, (char)(temp+'0'));
i--;
j--;
}
while(i>=0){
a=s1.charAt(i)-'0';
temp=a+add;
add=temp/10;
temp=temp%10;
sb.insert(0, (char)(temp+'0'));
i--;
}
while(j>=0){
b=s1.charAt(j)-'0';
temp=b+add;
add=temp/10;
temp=temp%10;
sb.insert(0, (char)(temp+'0'));
j--;
}
if(add!=0){
sb.insert(0, (char)(add+'0'));
}
return sb.toString();
}
}
超长正整数相加
最新推荐文章于 2019-11-20 19:30:58 发布