-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// https://school.programmers.co.kr/learn/courses/30/lessons/84512?language=java | ||
// 완전탐색 | ||
// 모음사전 | ||
|
||
|
||
// 문제 설명 | ||
// 사전에 알파벳 모음 'A', 'E', 'I', 'O', 'U'만을 사용하여 만들 수 있는, 길이 5 이하의 모든 단어가 수록되어 있습니다. 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA"이며, 마지막 단어는 "UUUUU"입니다. | ||
// 단어 하나 word가 매개변수로 주어질 때, 이 단어가 사전에서 몇 번째 단어인지 return 하도록 solution 함수를 완성해주세요. | ||
|
||
// 제한사항 | ||
// word의 길이는 1 이상 5 이하입니다. | ||
// word는 알파벳 대문자 'A', 'E', 'I', 'O', 'U'로만 이루어져 있습니다. | ||
// 입출력 예 | ||
// word result | ||
// "AAAAE" 6 | ||
// "AAAE" 10 | ||
// "I" 1563 | ||
// "EIO" 1189 | ||
|
||
// 입출력 예 설명 | ||
// 입출력 예 #1 | ||
// 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA", "AAA", "AAAA", "AAAAA", "AAAAE", ... 와 같습니다. "AAAAE"는 사전에서 6번째 단어입니다. | ||
|
||
// 입출력 예 #2 | ||
// "AAAE"는 "A", "AA", "AAA", "AAAA", "AAAAA", "AAAAE", "AAAAI", "AAAAO", "AAAAU"의 다음인 10번째 단어입니다. | ||
|
||
// 입출력 예 #3 | ||
// "I"는 1563번째 단어입니다. | ||
|
||
// 입출력 예 #4 | ||
// "EIO"는 1189번째 단어입니다. | ||
|
||
|
||
import java.util.*; | ||
|
||
class Solution { | ||
private List<String> dictionary = new ArrayList<>(); | ||
|
||
public int solution(String word) { | ||
|
||
addDictionary("", ""); | ||
|
||
return dictionary.indexOf(word); | ||
} | ||
|
||
private void addDictionary(String word, String character) { | ||
if(!dictionary.contains(word)) { | ||
dictionary.add(word); | ||
// System.out.println(word); | ||
} | ||
|
||
if (word.length() == 5) { | ||
return; | ||
} | ||
|
||
addDictionary(word + character, "A"); | ||
addDictionary(word + character, "E"); | ||
addDictionary(word + character, "I"); | ||
addDictionary(word + character, "O"); | ||
addDictionary(word + character, "U"); | ||
} | ||
} |