Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 운영체제
- 웹 프로그래밍
- annotation
- 자바 알고리즘
- linux
- jpa
- spring
- 메모리 관리
- Inverted Page Table
- Shared Page
- 2단계 Page Table
- 프로세스 할당
- 리눅스
- 자바 문제풀이
- CS
- 스프링
- Allocation of Physical Memory
- 스프링부트
- Segmentation with Paging
- 메모리의 불연속적 할당
- 알고리즘
- Page Table의 구현
- 프로세스 동기화
- 다단계 페이지 테이블
- 웹개발
- 프로세스 불연속 할당
- 코드스테이츠 백엔드 과정 39기
- Effective Access Time
- springboot
- 문제풀이
Archives
- Today
- Total
GrowMe
[PS] 백준 2338번 본문
💡백준 2338번 : A, B 입력받아, A+B, A-B, A*B 구하기

*Try 1
import java.util.*;
public class B5_2338 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
sc.close();
if(A > -1000 && A < 1000 && B > -1000 && B < 1000) {
System.out.println(A + B);
System.out.println(A - B);
System.out.println(A * B);
}
}
}

*Search
도대체 뭐가 문제일까?.. InputMismatch라는 걸 보니, 입력받는 타입이 문제인 것 같다. 1000자리를 넘지 않는 다는 말이 숫자 1000이 아니고, 자릿수로 1000이면 int / long 타입으로는 해결되지 않을 것 같다. BigInteger을 써보자.


BigInteger은 문자열 타입이기에 연산이 불가능. 따라서 BigInteger 클래스 내부 메서드 활용.
*Try 2
import java.util.*;
import java.math.BigInteger;
public class B5_2338 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger bignumber = new BigInteger("1000");
BigInteger A = sc.nextBigInteger();
BigInteger B = sc.nextBigInteger();
sc.close();
System.out.println(A.add(B));
System.out.println(A.subtract(B));
System.out.println(A.multiply(B));
}
}

Success Solving the Problem!
*후기
문제의 의미를 정확하게 이해하는 것이 중요하고, 에러의 종류가 무엇인지 의미를 생각해보는 것도 중요함을 느꼈다. 더불어, 앞서 풀이했던 문제를 통해 얻은 BigInteger 개념이 떠올라 문제풀이에 성공하며, 문제풀이를 통해 알게된 메서드나 개념들이 추후에도 도움될 것이라는 확신 또한 얻었다.
*Insight
- 에러의 의미를 파악해 수정사항 파악
- BigInteger 클래스의 활용
- Input 타입을 잘 받자
'Algorithm Thinking' 카테고리의 다른 글
[PS] 짐 나르기 문제 (0) | 2022.06.22 |
---|---|
[PS] 소수 출력 (0) | 2022.06.22 |
[PS]백준 1550번 (0) | 2022.06.22 |
[PS] 백준 1271번 (0) | 2022.06.22 |
[PS]백준-1000 (0) | 2022.06.14 |