Skip to content

Commit 6b88ba5

Browse files
committed
[level 3] Title: 불량 사용자, Time: 9021.97 ms, Memory: 16.5 MB -BaekjoonHub
1 parent d1463e8 commit 6b88ba5

2 files changed

Lines changed: 287 additions & 0 deletions

File tree

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# [level 3] 불량 사용자 - 64064
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/64064)
4+
5+
### 성능 요약
6+
7+
메모리: 16.5 MB, 시간: 9021.97 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 2019 카카오 개발자 겨울 인턴십
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2025년 05월 24일 15:33:11
20+
21+
### 문제 설명
22+
23+
<p>개발팀 내에서 이벤트 개발을 담당하고 있는 "무지"는 최근 진행된 카카오이모티콘 이벤트에 비정상적인 방법으로 당첨을 시도한 응모자들을 발견하였습니다. 이런 응모자들을 따로 모아 <code>불량 사용자</code>라는 이름으로 목록을 만들어서 당첨 처리 시 제외하도록 이벤트 당첨자 담당자인 "프로도" 에게 전달하려고 합니다. 이 때 개인정보 보호을 위해 사용자 아이디 중 일부 문자를 '*' 문자로 가려서 전달했습니다. 가리고자 하는 문자 하나에 '*' 문자 하나를 사용하였고 아이디 당 최소 하나 이상의 '*' 문자를 사용하였습니다.<br>
24+
"무지"와 "프로도"는 불량 사용자 목록에 매핑된 응모자 아이디를 <code>제재 아이디</code> 라고 부르기로 하였습니다.</p>
25+
26+
<p>예를 들어, 이벤트에 응모한 전체 사용자 아이디 목록이 다음과 같다면</p>
27+
<table class="table">
28+
<thead><tr>
29+
<th>응모자 아이디</th>
30+
</tr>
31+
</thead>
32+
<tbody><tr>
33+
<td>frodo</td>
34+
</tr>
35+
<tr>
36+
<td>fradi</td>
37+
</tr>
38+
<tr>
39+
<td>crodo</td>
40+
</tr>
41+
<tr>
42+
<td>abc123</td>
43+
</tr>
44+
<tr>
45+
<td>frodoc</td>
46+
</tr>
47+
</tbody>
48+
</table>
49+
<p>다음과 같이 불량 사용자 아이디 목록이 전달된 경우,</p>
50+
<table class="table">
51+
<thead><tr>
52+
<th>불량 사용자</th>
53+
</tr>
54+
</thead>
55+
<tbody><tr>
56+
<td>fr*d*</td>
57+
</tr>
58+
<tr>
59+
<td>abc1**</td>
60+
</tr>
61+
</tbody>
62+
</table>
63+
<p>불량 사용자에 매핑되어 당첨에서 제외되어야 야 할 제재 아이디 목록은 다음과 같이 두 가지 경우가 있을 수 있습니다.</p>
64+
<table class="table">
65+
<thead><tr>
66+
<th>제재 아이디</th>
67+
</tr>
68+
</thead>
69+
<tbody><tr>
70+
<td>frodo</td>
71+
</tr>
72+
<tr>
73+
<td>abc123</td>
74+
</tr>
75+
</tbody>
76+
</table><table class="table">
77+
<thead><tr>
78+
<th>제재 아이디</th>
79+
</tr>
80+
</thead>
81+
<tbody><tr>
82+
<td>fradi</td>
83+
</tr>
84+
<tr>
85+
<td>abc123</td>
86+
</tr>
87+
</tbody>
88+
</table>
89+
<p>이벤트 응모자 아이디 목록이 담긴 배열 user_id와 불량 사용자 아이디 목록이 담긴 배열 banned_id가 매개변수로 주어질 때, 당첨에서 제외되어야 할 제재 아이디 목록은 몇가지 경우의 수가 가능한 지 return 하도록 solution 함수를 완성해주세요.</p>
90+
91+
<h4><strong>[제한사항]</strong></h4>
92+
93+
<ul>
94+
<li>user_id 배열의 크기는 1 이상 8 이하입니다.</li>
95+
<li>user_id 배열 각 원소들의 값은 길이가 1 이상 8 이하인 문자열입니다.
96+
97+
<ul>
98+
<li>응모한 사용자 아이디들은 서로 중복되지 않습니다.</li>
99+
<li>응모한 사용자 아이디는 알파벳 소문자와 숫자로만으로 구성되어 있습니다.</li>
100+
</ul></li>
101+
<li>banned_id 배열의 크기는 1 이상 user_id 배열의 크기 이하입니다.</li>
102+
<li>banned_id 배열 각 원소들의 값은 길이가 1 이상 8 이하인 문자열입니다.
103+
104+
<ul>
105+
<li>불량 사용자 아이디는 알파벳 소문자와 숫자, 가리기 위한 문자 '*' 로만 이루어져 있습니다.</li>
106+
<li>불량 사용자 아이디는 '*' 문자를 하나 이상 포함하고 있습니다.</li>
107+
<li>불량 사용자 아이디 하나는 응모자 아이디 중 하나에 해당하고 같은 응모자 아이디가 중복해서 제재 아이디 목록에 들어가는 경우는 없습니다.</li>
108+
</ul></li>
109+
<li>제재 아이디 목록들을 구했을 때 아이디들이 나열된 순서와 관계없이 아이디 목록의 내용이 동일하다면 같은 것으로 처리하여 하나로 세면 됩니다.</li>
110+
</ul>
111+
112+
<hr>
113+
114+
<h5><strong>[입출력 예]</strong></h5>
115+
<table class="table">
116+
<thead><tr>
117+
<th>user_id</th>
118+
<th>banned_id</th>
119+
<th>result</th>
120+
</tr>
121+
</thead>
122+
<tbody><tr>
123+
<td><code>["frodo", "fradi", "crodo", "abc123", "frodoc"]</code></td>
124+
<td><code>["fr*d*", "abc1**"]</code></td>
125+
<td>2</td>
126+
</tr>
127+
<tr>
128+
<td><code>["frodo", "fradi", "crodo", "abc123", "frodoc"]</code></td>
129+
<td><code>["*rodo", "*rodo", "******"]</code></td>
130+
<td>2</td>
131+
</tr>
132+
<tr>
133+
<td><code>["frodo", "fradi", "crodo", "abc123", "frodoc"]</code></td>
134+
<td><code>["fr*d*", "*rodo", "******", "******"]</code></td>
135+
<td>3</td>
136+
</tr>
137+
</tbody>
138+
</table>
139+
<h5><strong>입출력 예에 대한 설명</strong></h5>
140+
141+
<h5><strong>입출력 예 #1</strong></h5>
142+
143+
<p>문제 설명과 같습니다.</p>
144+
145+
<h5><strong>입출력 예 #2</strong></h5>
146+
147+
<p>다음과 같이 두 가지 경우가 있습니다.</p>
148+
<table class="table">
149+
<thead><tr>
150+
<th>제재 아이디</th>
151+
</tr>
152+
</thead>
153+
<tbody><tr>
154+
<td>frodo</td>
155+
</tr>
156+
<tr>
157+
<td>crodo</td>
158+
</tr>
159+
<tr>
160+
<td>abc123</td>
161+
</tr>
162+
</tbody>
163+
</table><table class="table">
164+
<thead><tr>
165+
<th>제재 아이디</th>
166+
</tr>
167+
</thead>
168+
<tbody><tr>
169+
<td>frodo</td>
170+
</tr>
171+
<tr>
172+
<td>crodo</td>
173+
</tr>
174+
<tr>
175+
<td>frodoc</td>
176+
</tr>
177+
</tbody>
178+
</table>
179+
<h5><strong>입출력 예 #3</strong></h5>
180+
181+
<p>다음과 같이 세 가지 경우가 있습니다.</p>
182+
<table class="table">
183+
<thead><tr>
184+
<th>제재 아이디</th>
185+
</tr>
186+
</thead>
187+
<tbody><tr>
188+
<td>frodo</td>
189+
</tr>
190+
<tr>
191+
<td>crodo</td>
192+
</tr>
193+
<tr>
194+
<td>abc123</td>
195+
</tr>
196+
<tr>
197+
<td>frodoc</td>
198+
</tr>
199+
</tbody>
200+
</table><table class="table">
201+
<thead><tr>
202+
<th>제재 아이디</th>
203+
</tr>
204+
</thead>
205+
<tbody><tr>
206+
<td>fradi</td>
207+
</tr>
208+
<tr>
209+
<td>crodo</td>
210+
</tr>
211+
<tr>
212+
<td>abc123</td>
213+
</tr>
214+
<tr>
215+
<td>frodoc</td>
216+
</tr>
217+
</tbody>
218+
</table><table class="table">
219+
<thead><tr>
220+
<th>제재 아이디</th>
221+
</tr>
222+
</thead>
223+
<tbody><tr>
224+
<td>fradi</td>
225+
</tr>
226+
<tr>
227+
<td>frodo</td>
228+
</tr>
229+
<tr>
230+
<td>abc123</td>
231+
</tr>
232+
<tr>
233+
<td>frodoc</td>
234+
</tr>
235+
</tbody>
236+
</table>
237+
238+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Foundation
2+
3+
func solution(_ user_id:[String], _ banned_id:[String]) -> Int {
4+
5+
var ids: [[String]] = Array(repeating: [], count: banned_id.count)
6+
7+
for (bIndex, banned) in banned_id.enumerated() {
8+
//dot 위치 구하기
9+
var dotIndex: [Bool] = Array(repeating: false, count: banned.count)
10+
for (i, ch) in banned.enumerated() {
11+
dotIndex[i] = (ch == "*")
12+
}
13+
14+
//제재 아이디 구하기
15+
for user in user_id {
16+
if banned.count != user.count {
17+
continue
18+
}
19+
20+
let userString = user.enumerated().map { (index, ch)->String in
21+
return dotIndex[index] ? "*" : String(ch)
22+
}.joined()
23+
24+
if userString == banned {
25+
ids[bIndex].append(user)
26+
}
27+
}
28+
}
29+
30+
var results: Set<[String]> = []
31+
32+
//조합 구하기
33+
func banResult(banIds: Set<String>, index: Int) {
34+
for bannedId in ids[index] {
35+
var newBanIds = banIds
36+
newBanIds.insert(bannedId)
37+
38+
if newBanIds.count == ids.count {
39+
results.insert(newBanIds.sorted())
40+
} else if index+1 < ids.count {
41+
banResult(banIds: newBanIds, index: index+1)
42+
}
43+
}
44+
}
45+
46+
banResult(banIds: [], index: 0)
47+
48+
return results.count
49+
}

0 commit comments

Comments
 (0)