• 문제 링크
1515번: 수 이어 쓰기
세준이는 1부터 N까지 모든 수를 차례대로 공백없이 한 줄에 다 썼다. 그리고 나서, 세준이가 저녁을 먹으러 나간 사이에 다솜이는 세준이가 쓴 수에서 마음에 드는 몇 개의 숫자를 지웠다. 세준
www.acmicpc.net
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
static String s;
static int idx;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
s = br.readLine();
int n = 0;
while (n++ < 30001) if (contains(String.valueOf(n))) break;
bw.write(String.valueOf(n));
bw.flush();
}
private static boolean contains(String n) {
for (int i = 0; i < n.length(); i++) {
if (n.charAt(i) == s.charAt(idx)) idx++;
if (idx == s.length()) return true;
}
return false;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 19564 반복 - Greedy / Java (0) | 2023.08.20 |
---|---|
[백준] 15729 방탈출 - Greedy / Java (0) | 2023.08.19 |
[백준] 15881 Pen Pineapple Apple Pen - Greedy / Java (0) | 2023.08.17 |
[백준] 25400 제자리 - Greedy / Java (0) | 2023.08.16 |
[백준] 2810 컵홀더 - Greedy / Java (0) | 2023.08.15 |
댓글