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
- Segmentation with Paging
- Effective Access Time
- 스프링부트
- 문제풀이
- 코드스테이츠 백엔드 과정 39기
- 자바 문제풀이
- 스프링
- annotation
- spring
- jpa
- Allocation of Physical Memory
- linux
- 웹개발
- 프로세스 불연속 할당
- 운영체제
- 메모리의 불연속적 할당
- 리눅스
- 웹 프로그래밍
- Page Table의 구현
- 프로세스 동기화
- springboot
- Inverted Page Table
- Shared Page
- 알고리즘
- 2단계 Page Table
- 자바 알고리즘
- 프로세스 할당
- 메모리 관리
- CS
- 다단계 페이지 테이블
Archives
- Today
- Total
GrowMe
[PS] 백준 1271번 본문
💡백준 1271번 : 정수 A와 B를 입력 받아 덧셈 후 출력하기
*Try 1
import java.util.*;
public class B5_1271 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m;
int n;
m = sc.nextInt();
n = sc.nextInt();
if(m >= 1 && m <= Math.pow(10, 1000) && n >= 1 && n <= Math.pow(10, 1000) ){
System.out.println((m / n));
System.out.println((m % n));
}
sc.close();
}
}
*Search
m과 n의 범위 ≤ 10^1000 이걸 Int 타입에 넣는게 가능한가??
long 타입으로도 불가능. 따라서 큰 정수를 담을 수 있는 방법을 검색하였다.
—> BigInteger를 활용해야하는구나!
■BigInteger 활용법
BigInteger을 초기화하기 위해서는 문자열을 인자 값으로 넘겨주어야 한다. BigInteger가 문자열로 되어 있기 때문.
BigInteger은 문자열 타입이기에 연산이 불가능. 따라서 BigInteger 클래스 내부 메서드 활용.
*Try 2
import java.util.*;
import java.math.BigInteger;
public class B5_1271 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger bigNumber = new BigInteger("1000");
BigInteger m = sc.nextBigInteger();
BigInteger n = sc.nextBigInteger();
sc.close();
System.out.println(m.divide(n));
System.out.println(m.remainder(n));
}
}
Success Solving the Problem!
*후기
쉬워보이는 문제도 조건을 보며 하나하나 따져가며 생각을 해야한다고 느꼈다. 갈길이 아직 멀다. 힘내자 💪
*Insight
- 문제풀이 시, 사소한 조건의 중요성
- BigInteger 클래스의 활용법
- 정수를 문자열로도 받을 수가 있고, 범위가 무한대이구나
- Scanner의 close() 메서드의 위치
'Algorithm Thinking' 카테고리의 다른 글
[PS] 짐 나르기 문제 (0) | 2022.06.22 |
---|---|
[PS] 소수 출력 (0) | 2022.06.22 |
[PS] 백준 2338번 (0) | 2022.06.22 |
[PS]백준 1550번 (0) | 2022.06.22 |
[PS]백준-1000 (0) | 2022.06.14 |
Comments