BEAKJOON
백준(1436번 영화감독 숌)풀이 C++
Shin_jisoo
2021. 1. 17. 22:46
728x90
1436번: 영화감독 숌
666은 종말을 나타내는 숫자라고 한다. 따라서, 많은 블록버스터 영화에서는 666이 들어간 제목을 많이 사용한다. 영화감독 숌은 세상의 종말 이라는 시리즈 영화의 감독이다. 조지 루카스는 스타
www.acmicpc.net
1) 주석 없는 VERSION
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[]) {
int n;
int count = 0;
int title = 665;
string s;
cin >> n;
while (++title) {
s = to_string(title);
if (s.find("666") != -1) {
++count;
}
if (count == n) {
cout << title << endl;
break;
}
}
return 0;
}
2) 주석 있는 VERSION
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[]) {
int n;
int count = 0;
int title = 665;
string s;
cin >> n;
// 숫자를 1씩 늘려가면서
while (++title) {
// title 을 string 으로 받아옴
s = to_string(title);
// 666을 포함하는 숫자인경우
if (s.find("666") != -1) {
// 카운트 세기
++count;
}
// 카운트가 입력한 숫자와 같아질 경우
if (count == n) {
// title 출력
cout << title << endl;
break;
}
}
return 0;
}