[백준 1436번: 영화감독 숌] java풀이

Elmo·2022년 7월 23일
0

[백준] 알고리즘

목록 보기
6/39

숫자를 문자열로 변환하는 방법을 알면 쉽게 푸는 간단한 문제

숫자를 문자열로 변환한 후 그 문자열에 "666"이 포함되어 있는지를 검사만하면 된다. 반복문은 쉽게 While(true)를 이용하였다.

자바에서 숫자를 문자열로 변환하는 방법

  1. String s = Integer.toSring(i);

  2. String s = String.valueOf(i);

🔑 java 풀이

import java.util.Scanner;
public class Main {
	
	int Search(int N) {
		int i=0;
		int count=0;
		while(true) {
			if(Integer.toString(i).contains("666")) {
				count++;
			}
			if(count==N)
				return i;
			i++;
		}
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main Main = new Main();
		
		int N = sc.nextInt();
		
		System.out.println(Main.Search(N));
		sc.close();
	}

}
profile
엘모는 즐거워

0개의 댓글