문제

https://school.programmers.co.kr/learn/courses/30/lessons/84512

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

char spell[5] = { 'A','E','I','O','U' };
char arr[5];
vector<string> dir;
void Permutation(int depth,int n, int r) {
    if (depth == r) {
        string s = "";
        for (int j = 0; j < r; j++)
            s.push_back(arr[j]);
        dir.push_back(s);
        return;
    }

    for (int i = 0; i < n; i++) {
        arr[depth] = spell[i];
        Permutation(depth + 1, n, r);
    }
}


int solution(string word) {

    for (int i = 0; i <= 5; i++)    
        Permutation(0, 5, i);
    
    sort(dir.begin(), dir.end());

    for (int j = 0; j < dir.size(); j++)    
        if (dir[j] == word) return j;
    

    return -1;
}
Posted by pi92

블로그 이미지
pi92

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.5
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함