https://www.acmicpc.net/problem/15740



◎알고리즘 [풀이과정]
A+B 값을 더해서 출력만 해주면 되기 때문에 간단한 문제이지만 여기서 주의해야 할 점은 입력할 수 있는 값의 크기가 굉장히 크다는 것이다.
(-1010000 ≤ A, B ≤ 1010000) 이는 int형은 물론 long형을 사용하더라도 값을 전부 담을수 없다.
따라서 BigInteger라는 math를 참조하여 문제를 해결해야 한다.
import java.util.Scanner;
import java.math.*;
public class st_15740 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger a = new BigInteger(sc.next());
BigInteger b = new BigInteger(sc.next());
System.out.println(a.add(b));
}
}'알고리즘 > 랜덤 마라톤' 카테고리의 다른 글
| [백준] 6030번: Scavenger Hunt - JAVA[랜덤 마라톤] (0) | 2024.08.23 |
|---|---|
| [백준] 18330번: Petrol - JAVA[랜덤 마라톤] (0) | 2024.08.23 |
| [백준] 24736번: Football Scoring - JAVA[랜덤 마라톤] (0) | 2024.08.23 |
| [백준] 11382번: 꼬마 정민 - JAVA[랜덤 마라톤] (0) | 2024.08.23 |
| [백준] 25377번: 빵 - JAVA[랜덤 마라톤] (0) | 2024.08.21 |