size_type find(const basic_string& str, size_type pos = 0) const;
문자열에서 str을 찾아 시작 위치를 반환한다.
str를 찾지 못했을 경우 str::npos를 반환한다.
npos는 size_t type이며 unsigned int의 최댓값이다 (4294967295, 2^32-1).
이것을 int로 변환하면 -1이 된다.
다음과 같이 활용할 수 있다.
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
cin >> N;
int cnt = 0;
int ans = 0;
while (1) {
ans++;
string str = to_string(ans);
if (str.find("666") != -1) {
cnt++;
if (cnt == N) {
cout << str << '\n';
break;
}
}
}
}
https://www.acmicpc.net/problem/1436
1436번: 영화감독 숌
666은 종말을 나타내는 수라고 한다. 따라서, 많은 블록버스터 영화에서는 666이 들어간 제목을 많이 사용한다. 영화감독 숌은 세상의 종말 이라는 시리즈 영화의 감독이다. 조지 루카스는 스타워
www.acmicpc.net