프로그래머스(코테준비)
프로그래머스 모음사전/DFS/C++
급하게
2024. 9. 3. 23:58
이 문제의 경우 처음에 for문을 연달아 쓰려 했으나 그렇게 할봐에 차라리 재귀를 통한 진행이 맞을 것이라고 판단하였다
#include <string>
#include <vector>
#include <string>
using namespace std;
int cnt=-1;
int answer=0;
string target="";
string aeiou="AEIOU";
void dfs(string word){
cnt+=1;
if(target==word){
answer=cnt;
return;
}
if(word.length()>=5)
return;
for(int i=0; i<5; i++){
dfs(word+aeiou[i]);
}
}
int solution(string word) {
target=word;
dfs("");
return answer;
}