★ 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++ 업데이트
'C, C++ > 🥈 BOJ' 카테고리의 다른 글
(C++) ★Stack & Queue & Deque Intermediate I - 4 Solved★ (0) | 2024.11.15 |
---|---|
(C++) ★Number Theory Intermediate I - 2 Solved★ (0) | 2024.11.15 |
(C++) ★Set/Map Intermediate I - 5 Solved★ (2) | 2024.11.14 |
(C++) ★Sorting Intermediate I - 5 Solved★ (0) | 2024.11.14 |
(C++) ★Implementation&Simulation Intermediate I - 2 Solved★ (0) | 2024.11.14 |
댓글