# 문제 설명
- A, B < 10^10_000 : A,B는 자릿수가 10000자리 수
- Java의 long 은 64bits => 2^64까지 표현가능
- 즉, 기본자료형으로는 입력조차 받기 버겁다. (String으로 받아줘야 한다)
- 단순 구현 문제이다.
# 접근 방법
- String으로 A와 B를 받은 후, 각 자릿수를 더해 다시 String으로 리턴 해주면 된다.
- 굳이 클래스를 정의하지 않아도 되나, 필자는 클래스 문법을 한번 더 복습하는 겸, 클래스로 구현했다.
- Tip1) 초등학교때 배운것처럼 1의 자리부터 덧셈하자..! (즉 계산은 String의 가장 끝 인덱스로 부터 시작한다)
- Tip2) 10자리수와 10자리수를 더하면 11자리수가 되거나 10자리 수가 된다.
# 구현 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main{
static class BigInt{
int[] digit;
public BigInt(String num){
this.digit= new int[num.length()];
int idx=0;
for(int i=num.length()-1;i>=0;i--){ //insert reversely
this.digit[idx++]=(num.charAt(i)-'0');
}
}
public BigInt(int size){
this.digit= new int[size];
}
public void printDigit(){ //should print from the end.
if(digit[digit.length-1] !=0) System.out.print(digit[digit.length-1]);
for(int i=digit.length-2;i>=0;i--){
System.out.print(digit[i]);
}
System.out.println();
}
}
static BigInt plus(BigInt LONG, BigInt SHORT){
BigInt C= new BigInt(LONG.digit.length+1);
int remain=0;
for(int i=0; i<SHORT.digit.length; i++){ //거꾸로넣은숫자를 더한다..! 명심하도록 ㅇㅋㅇㅋ?
C.digit[i]=(LONG.digit[i]+SHORT.digit[i]+remain)%10;
remain=(LONG.digit[i]+SHORT.digit[i]+remain)/10;
}
for(int i=SHORT.digit.length;i<LONG.digit.length;i++){
C.digit[i]= (LONG.digit[i]+remain) %10;
remain = (LONG.digit[i]+remain)/10;
}
C.digit[C.digit.length-1] = remain;
return C;
}
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String A = st.nextToken();
String B = st.nextToken();
BigInt bigA = new BigInt(A);
BigInt bigB = new BigInt(B);
BigInt result;
if(A.length()>=B.length()){
result=plus(bigA,bigB);
}else{
result=plus(bigB,bigA);
}
result.printDigit();
//a,b <= 10^10_000 (0이 몇개지 ㅋㅋㅋㅋ 10^2이 2개 10^3이 3개, 0이 10_000개)
// 즉 10_001 자리수
}
}