[SWEA] 두 수의 덧셈

문제 보러가기

제한사항

이외의 제한사항은 없다.

첫번째 생각

문제를 처음 읽고 말도안되게 쉬운 문제라고 생각했는데 정수의 범위가 10^100이었다.

BigInteger를 사용해서 문제를 풀이하였고, BigInteger의 동작원리에 대해 알아보아야겠다.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.math.BigInteger;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int tc=1; tc<=T; tc++) {
			BigInteger A = new BigInteger(sc.next());
			BigInteger B = new BigInteger(sc.next());

			System.out.println("#"+tc+" "+A.add(B));
		}
	}
}