Skip to content

Commit a003bb4

Browse files
committed
[level 2] Title: 모음 사전, Time: 5.66 ms, Memory: 78 MB -BaekjoonHub
1 parent 6666e3b commit a003bb4

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [level 2] 모음 사전 - 84512
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/84512)
4+
5+
### 성능 요약
6+
7+
메모리: 78 MB, 시간: 5.66 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 완전탐색
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 02월 16일 18:25:13
20+
21+
### 문제 설명
22+
23+
<p>사전에 알파벳 모음 'A', 'E', 'I', 'O', 'U'만을 사용하여 만들 수 있는, 길이 5 이하의 모든 단어가 수록되어 있습니다. 사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA"이며, 마지막 단어는 "UUUUU"입니다.</p>
24+
25+
<p>단어 하나 word가 매개변수로 주어질 때, 이 단어가 사전에서 몇 번째 단어인지 return 하도록 solution 함수를 완성해주세요.</p>
26+
27+
<h5>제한사항</h5>
28+
29+
<ul>
30+
<li>word의 길이는 1 이상 5 이하입니다.</li>
31+
<li>word는 알파벳 대문자 'A', 'E', 'I', 'O', 'U'로만 이루어져 있습니다.</li>
32+
</ul>
33+
34+
<hr>
35+
36+
<h5>입출력 예</h5>
37+
<table class="table">
38+
<thead><tr>
39+
<th>word</th>
40+
<th>result</th>
41+
</tr>
42+
</thead>
43+
<tbody><tr>
44+
<td><code>"AAAAE"</code></td>
45+
<td>6</td>
46+
</tr>
47+
<tr>
48+
<td><code>"AAAE"</code></td>
49+
<td>10</td>
50+
</tr>
51+
<tr>
52+
<td><code>"I"</code></td>
53+
<td>1563</td>
54+
</tr>
55+
<tr>
56+
<td><code>"EIO"</code></td>
57+
<td>1189</td>
58+
</tr>
59+
</tbody>
60+
</table>
61+
<h5>입출력 예 설명</h5>
62+
63+
<p>입출력 예 #1</p>
64+
65+
<p>사전에서 첫 번째 단어는 "A"이고, 그다음은 "AA", "AAA", "AAAA", "AAAAA", "AAAAE", ... 와 같습니다. "AAAAE"는 사전에서 6번째 단어입니다.</p>
66+
67+
<p>입출력 예 #2</p>
68+
69+
<p>"AAAE"는 "A", "AA", "AAA", "AAAA", "AAAAA", "AAAAE", "AAAAI", "AAAAO", "AAAAU"의 다음인 10번째 단어입니다.</p>
70+
71+
<p>입출력 예 #3</p>
72+
73+
<p>"I"는 1563번째 단어입니다.</p>
74+
75+
<p>입출력 예 #4</p>
76+
77+
<p>"EIO"는 1189번째 단어입니다.</p>
78+
79+
80+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class Solution {
2+
String target;
3+
int count=0;
4+
boolean found = false;
5+
char[] vowels = {'A','E','I','O','U'};
6+
7+
public int solution(String target) {
8+
this.target=target;
9+
dfs("");
10+
return count;
11+
}
12+
13+
void dfs(String word){
14+
// count++;
15+
16+
if(found == true){
17+
return;
18+
}
19+
20+
// if(word.equals(target)){ //단어 찾았을 때
21+
// found = true;
22+
// return;
23+
// }
24+
25+
// 빈 문자열이 아닐 때만 카운트
26+
if(!word.equals("")){
27+
count++;
28+
if(word.equals(target)){
29+
found = true;
30+
return;
31+
}
32+
}
33+
34+
35+
if(word.length() == 5){ //길이 5 넘어갈때
36+
return;
37+
}
38+
39+
40+
dfs(word+"A");
41+
dfs(word+"E");
42+
dfs(word+"I");
43+
dfs(word+"O");
44+
dfs(word+"U");
45+
46+
return;
47+
}
48+
}

0 commit comments

Comments
 (0)