백준 1436번 문제, 영화감독 숌
666이라는 문자열을 가지고 있는 수 중 N번째로 작은 수를 출력하는 문제이다.
C++ string 클래스에 대한 이해가 부족하여 빙빙 돌아가는 풀이로 풀게되었다.
총평) * string class 의 to_string : to_문자열
* 아스키코드 6과 char type '6'을 헷갈리면 안된다(문자와 숫자를 비교할 때 어떻게 비교되는지 신경쓰기).
string class의 find 멤버함수를 직접 구현해놓은(?) 느낌이다.
#include <iostream>
#include <string>
using namespace std;
int main() {
int N; cin >> N;
string input;
bool deter = false;
int hellcount = 0;
for (int i = 666; true; i++) {
input = to_string(i);
int counter = 0;
for (int j = 0; j < input.length(); j++) {
if (input[j] == '6') {
counter++;
}
else {
counter = 0;
}
if (counter >= 3) {
deter = true;
break;
}
else {
deter = false;
}
}
if (deter == true) {
hellcount++;
}
if (N == hellcount) {
cout << i;
return 0;
}
}
return 0;
}
'알고리즘 > 백준' 카테고리의 다른 글
[Baekjoon] 1929_소수 구하기 (0) | 2022.04.11 |
---|---|
[Baekjoon] github repository 생성 (0) | 2022.04.08 |
백준 단계별 풀이 (0) | 2022.03.13 |
백준 단계별 풀이 (0) | 2022.03.13 |