File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # [ Silver II] 수 이어 쓰기 - 1515
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/1515 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 15624 KB, 시간: 112 ms
8+
9+ ### 분류
10+
11+ 구현, 그리디 알고리즘, 문자열, 브루트포스 알고리즘
12+
13+ ### 제출 일자
14+
15+ 2026년 3월 7일 19:50:36
16+
17+ ### 문제 설명
18+
19+ <p >세준이는 1부터 N까지 모든 수를 차례대로 공백없이 한 줄에 다 썼다. 그리고 나서, 세준이가 저녁을 먹으러 나간 사이에 다솜이는 세준이가 쓴 수에서 마음에 드는 몇 개의 숫자를 지웠다.</p >
20+
21+ <p >세준이는 저녁을 먹으러 갔다 와서, 자기가 쓴 수의 일부가 지워져있는 모습을 보고 충격받았다.</p >
22+
23+ <p >세준이는 수를 방금 전과 똑같이 쓰려고 한다. 하지만, N이 기억이 나지 않는다.</p >
24+
25+ <p >남은 수를 이어 붙인 수가 주어질 때, N의 최솟값을 구하는 프로그램을 작성하시오. 아무것도 지우지 않을 수도 있다.)</p >
26+
27+ ### 입력
28+
29+ <p >첫째 줄에 지우고 남은 수를 한 줄로 이어 붙인 수가 주어진다. 이 수는 최대 3,000자리다.</p >
30+
31+ ### 출력
32+
33+ <p >가능한 N 중에 최솟값을 출력한다.</p >
34+
Original file line number Diff line number Diff line change 1+ import java .io .*;
2+
3+ public class Main {
4+ public static void main (String [] args ) throws Exception {
5+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
6+ char [] pollution = br .readLine ().toCharArray ();
7+
8+ System .out .println (findOrigin (pollution ));
9+ }
10+
11+ private static int findOrigin (char [] pollution ){
12+ int origin = 0 ;
13+ int digit = 0 ;
14+
15+ while (origin ++ <= 30000 ){
16+ String originStr = Integer .toString (origin );
17+
18+ for (int i = 0 ; i < originStr .length (); i ++){
19+ if (pollution [digit ] == originStr .charAt (i )) digit ++;
20+ if (digit == pollution .length ) return origin ;
21+ }
22+ }
23+ return origin ;
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments