문제
https://school.programmers.co.kr/learn/courses/30/lessons/84512
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 풀이
해당 문제는 최대 연산이 1만 이하인 케이스를 제시하고 있다. (모음 5개를 1에서 5자리 사이로 배치하는 경우 이므로)
그렇기에 DFS로 완전 탐색을 진행하면서 타겟 단어와 서치중인 단어가 같을 경우의 count를 반환하면 정답이 나온다.
#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<string> dic = {"A","E","I","O","U"};
string target;
int count = 0;
int result = 0;
void search (string str){
if(str.length() == 5) return;
for(int i = 0; i < 5; i++){
count++;
if(str+dic[i] == target){
result = count;
}
search(str + dic[i]);
}
}
int solution(string word) {
int answer = 0;
target = word;
search("");
return result;
}
'algorithm > problems' 카테고리의 다른 글
[프로그래머스 / C++] 이모티콘 할인행사 (0) | 2023.05.19 |
---|---|
[프로그래머스 / C++] 롤케이크 자르기 (0) | 2023.05.18 |
[프로그래머스 / C++] 피로도 (0) | 2023.05.17 |
[LeetCode] 258. Add Digits (0) | 2023.04.26 |
[백준]1107번 리모컨 (0) | 2022.11.26 |