forked from 2021-Algorithm/algorithms_site
-
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.
programmers/python/level3/kakao/2019/겨울인턴십_불량사용자.py
- Loading branch information
Showing
1 changed file
with
38 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,38 @@ | ||
## https://school.programmers.co.kr/learn/courses/30/lessons/64064 | ||
def solution(user_id, banned_id): | ||
|
||
cand = [[] for _ in range(len(banned_id))] | ||
for k, b_id in enumerate(banned_id): | ||
for j, u_id in enumerate(user_id): | ||
if len(b_id) == len(u_id): | ||
possible = True | ||
for i, v in enumerate(b_id): | ||
if v != "*" and v != u_id[i]: | ||
possible = False | ||
break | ||
if possible: | ||
cand[k].append(j) | ||
|
||
|
||
ans = set() | ||
|
||
def sol(turn, ret): | ||
if turn == len(banned_id): | ||
ans.add(str(ret)) | ||
return | ||
|
||
for can in cand[turn]: | ||
if ret[can] == 0: | ||
ret[can] = 1 | ||
sol(turn+1, ret) | ||
ret[can] = 0 | ||
|
||
ret = [0] * len(user_id) | ||
sol(0, ret) | ||
|
||
return len(ans) | ||
|
||
|
||
print(solution(["frodo", "fradi", "crodo", "abc123", "frodoc"], ["fr*d*", "abc1**"])) | ||
|
||
|