문제
https://www.acmicpc.net/problem/1436
풀이
숫자를 문자열로 변환하는 to_string + BruthForce 문제였다. 문자열과 숫자를 같이 생각해주면서 1씩 증가해보면서 모든 case를 판단해주면 된다. 문자열 변환을 해주지 않는다면 시간 초과가 날것이다.
코드
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int N;
int main() {
cin >> N;
int result = 0;
int K = 666;
while (1) {
string target=to_string(K);
for (int i = 0; i < target.size(); i++) {
if (target[i] == '6' && target[i + 1] == '6' && target[i + 2] == '6') {
result++;
break;
}
}
if (result == N) break;
K++;
}
cout << K;
return 0;
}
'알고리즘 공부 > 백준' 카테고리의 다른 글
[백준] 나무 자르기 (2805/C++) (0) | 2022.01.16 |
---|---|
[백준] 블랙잭 (2798 / C++) (0) | 2022.01.16 |
[백준] 랜선자르기 (1654 / C++) (0) | 2022.01.11 |
[백준] 스택 수열(1874/C++) (0) | 2022.01.09 |
[백준] 단어정렬 (C++/1181) (0) | 2021.12.19 |