• 문제 링크
12755번: 수면 장애
수면 장애를 가진 강민이는 잠이 오지 않아 적잖은 고통을 느끼고 있다. 강민이는 잠이 오지 않을 때마다 속으로 양을 세고 있었는데, 오늘따라 백만 마리까지 세었는데도 잠이 오지 않았다. 한
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), i = 0, len = 0;
do len += calcLen(++i); while (len < n);
len -= n;
while (len-- > 0) i /= 10;
bw.write(String.valueOf(i % 10));
bw.flush();
}
private static int calcLen(int i) {
int len = 0;
do len++; while ((i /= 10) > 0);
return len;
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 3711 학번 - Brute Force / Java (0) | 2023.11.26 |
---|---|
[백준] 5534 간판 - Brute Force / Java (0) | 2023.11.25 |
[백준] 25426 일차함수들 - Greedy / Java (0) | 2023.11.23 |
[백준] 25945 컨테이너 재배치 - Greedy / Java (0) | 2023.11.22 |
[백준] 29767 점수를 최대로 - Greedy / Java (0) | 2023.11.21 |
댓글