1436_영화감독 숌

bgy·2021년 12월 30일
0

백준

목록 보기
9/21

문자열로 바꿔서(to_string(int)) s.find(string) 함수로 찾기 or

#include <iostream> 
#include <string>
using namespace std;


int main() {
	int n;
	cin >> n;
	int first = 665;
	int res = 1;
	
	while (first++) {
		string s = to_string(first);
		
		if (s.find("666") != -1) {
			if (res == n) {
				cout << first;
				return 0;
			}
			res++;
		}
		
	}
}

앞에 3자리수만 남겨서 일의 자리수부터 지우기

#include <iostream> 
using namespace std;


int main() {
	int n;
	cin >> n;
	int first = 665;
	int res = 1;
	
	while (first++) {
		int title = first;
		while (title >= 666) {
			if (title % 1000 == 666) {
				if (res == n) {
					cout << first;
					return 0;
				}
				res++;
				break;
			}
			else title /= 10;
		}
	}
}

0개의 댓글