#include<iostream>
#include<string>
using namespace std;
int find(int N) {
int i = 666;
string target;
int count = 0;
while (1) {
target = to_string(i);
for (int j = 0; j < target.length()-2; j++) { //j<target.length()-2를 생각하기가 오래걸렸다.
if (target[j] == '6' && target[j + 1] == '6' && target[j + 2] == '6') {
count++;
if (count == N)
return i;
break; //이게 제일 중요한 것 같다. 6666일때 2번 카운트가 되기 때문이다.
}
}
i++;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
cout << find(N);
}
string을 int로 변경하는 stoi 함수
int를 string으로 변경하는 to_string 함수
'코딩테스트 > C++' 카테고리의 다른 글
백준 정렬 알고리즘 2750번 C++ (0) | 2024.03.02 |
---|---|
백준 브루트 포스 알고리즘 2839번 C++ (0) | 2024.02.29 |
백준 브루트 포스 알고리즘 19532번 C++ (0) | 2024.02.26 |
백준 브루트 포스 알고리즘 2231번 C++ (0) | 2024.02.26 |
백준 브루트 포스 알고리즘 2798번 C++ (0) | 2024.02.21 |