코딩공부/프로그래머스

※[프로그래머스]Lv.2 모음 사전 C#(순열)

usingsystem 2023. 7. 20. 17:51
728x90

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

 

프로그래머스

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

programmers.co.kr

소스코드

using System;
using System.Collections.Generic;
public class Solution
{
    List<string> list = new List<string>();
    public int solution(string word)
    {
        int answer = 0;
        for (int i = 1; i < 5 + 1; i++)
            Perm("AEIOU".ToCharArray(), "", 0, i);

        list.Sort();
        answer = list.FindIndex(f => f == word);

        return answer + 1;
    }
    void Perm(char[] array, string str, int depth, int k)
    {
        if (depth == k)
            list.Add(str);
        else
            for (int i = 0; i < array.Length; i++)
                Perm(array, str + array[i], depth + 1, k);
    }
}
728x90