C, C++/🥈 BOJ

(C++)★BF Intermediate I - 1 Solved★

metamong 2024. 11. 14.

★ 1436 영화감독 숌 ★

//1436
#include <iostream>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int N, n = 666, cnt = 1;
    string n_string;
    bool found = false;
    cin >> N;

    while(true){
        n_string = to_string(n);
        found = false;
        for(int x = 0; x < n_string.length()-2; x++){
            if(n_string[x] == '6' && n_string[x+1] == '6' && n_string[x+2] == '6'){
                if(cnt==N){
                    cout << n << endl;
                    return 0;
                }
                if(found == false){
                    cnt++;
                    found = true;
                    break;
                }
            }
        }
        n++;
    }

	return 0;
}

 

🧕🏼 주어진 숫자를 문자열 string으로 바꾸는 to_string() 함수 활용. string 문자열로 바꾼 뒤, index 0부터 문자열 length - 3까지 for문 돌린다(반복변수 x). 그리고 직접 확인. / 추가로 bool 변수 활용하여 주어진 숫자에서 연속된 666 찾았다면, 이 경우가 처음이라면(found == false) cnt++ 업데이트


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

댓글