백준 문제풀이

1436. 영화감독 숌 (자바, Java)

뮤츠 2022. 10. 2. 19:26

처음에 좀 막막했는데, String을 이용해 쉽게 풀었다.

String으로 '666'이 포함되는 수를 작은 수부터 검사하여, n과 같은 순번일때 반복문을 빠져나와 출력하는 식.

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());	// 입력값(영화제목이들어간수)읽어들이기
		int num = 0;
		int count = 0;
		
		for (int i=666; count!=n; i++) {
			
			if (String.valueOf(i).contains("666")) {
				
				num = i;
				count++;
								
			}
			
		}
		
		System.out.println(num);
								
	}
}