[BOJ 1515] ์ˆ˜์ด์–ด์“ฐ๊ธฐ

 

1. ๋ฌธ์ œ : https://www.acmicpc.net/problem/1515

 

2. ํ’€์ด

ํ•˜๋‚˜๋ผ๋„ ๋งค์นญ๋˜๋ฉด๋„˜์–ด๊ฐ€๋Š”๊ฒŒ ์ค‘์š”ํ–ˆ๋‹ค

ํฌ์ธํ„ฐ๊ฐ€ ๋‘๊ฐœ ํ•„์š”ํ•œ ๊ฒƒ๋„

 

3. ์ฝ”๋“œ

package baekjoon;

import java.util.*;
import java.io.*;

public class ์ˆ˜์ด์–ด์“ฐ๊ธฐ {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String num = br.readLine();

        int pt = 0;
        int base = 0;

        while (base <= 30000) {
            base++;
            String baseStr = String.valueOf(base);
            for (int i = 0; i < baseStr.length(); i++) {
                if (baseStr.charAt(i) == num.charAt(pt))
                    pt++;
                if (pt == num.length()) {
                    System.out.println(base);
                    return;
                }
            }
        }

    }
}
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ