0. 문제
1. 문제 이해
- 666
- 1666
- 2666
- 3666
- 4666
- 5666
- 6660
- 6661
- 6662
- 6663
- 6664
- 6665
- 6666
- 6667
- 6668
- 6669
- 7666
- 8666
- 9666
- 10666
- 11666
- 12666
- 13666
- 14666
- 15666
- 16660
- 16662
- 16663
…
??. 26660
…
??. 36660
…
??. 56669
??. 66600
??. 66601
제일 단순한 방법은 1씩 더해가면서 연속으로 6이 3번 나오는 경우를 찾는 것이다.
1씩 더해가면서 N번째 666 패턴이 나오면 반환하면 된다.
2. 제출
//백준 1436번: 영화감독 숌
#include<iostream>
#include<string>
using namespace std;
int n, i=666, cnt=1, ret=666;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n;
do{
i++;
string str = to_string(i);
auto it = str.find("666");
if(it != string::npos){
cnt++;
ret = i;
}
}while(cnt!=n);
cout << ret << "\n";
return 0;
}
Code language: PHP (php)
auto it = str.find("666");:string.find()를 활용해서 “666” 패턴이 존재하는지 확인한다.
