📝 문제
🔑 풀이 과정
for문으로 i를 1부터 계속 증가시킨다.
i를 문자열로 변환해서 "666"이 들어가면 count를 증가시킨다. (→ count 값 = 몇 번째 종말의 숫자인지 나타내는 값)
count값이 입력받은 N과 같아지면 현재 i값을 적고 반복문 탈출
🔓 답안
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int count = 0;
for(int i = 1; ; i++){
if(String.valueOf(i).contains("666"))
count++;
if(count == N){
bw.write(i + "\n");
break;
}
}
bw.flush();
bw.close();
}
}
🖤 알고리즘 분류
- 브루트포스 알고리즘
'PS > Baekjoon' 카테고리의 다른 글
[Baekjoon] 2953 - 나는 요리사다 (0) | 2023.02.10 |
---|---|
[Baekjoon] 17618 - 신기한 수 (0) | 2023.02.09 |
[Baekjoon] 1018 - 체스판 다시 칠하기 (0) | 2023.02.07 |
[Baekjoon] 7568 - 덩치 (0) | 2023.02.06 |
[Baekjoon] 1259 - 팰린드롬수 (0) | 2023.02.05 |
댓글