Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a773b36

Browse files
committed
이예진: [PG] 64064 불량 사용자_241127
1 parent 65c48c2 commit a773b36

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

‎Programmers/Level3/YJ_64064.java‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.util.*;
2+
3+
//user_id 배열의 크기는 1 이상 8 이하 > 8!
4+
public class YJ_64064 {
5+
HashSet<String> set = new HashSet<>();
6+
String[] userIds;
7+
String[] bannedIds;
8+
boolean[] visited;
9+
10+
public int solution(String[] user_id, String[] banned_id) {
11+
for(int i=0; i<banned_id.length; i++){
12+
banned_id[i] = banned_id[i].replace('*','.');
13+
}
14+
userIds = user_id;
15+
bannedIds = banned_id;
16+
visited = new boolean[user_id.length];
17+
18+
permutation(0, "");
19+
return set.size();
20+
}
21+
22+
//유저 수(n) 중에서 제재 수(r) 만큼 뽑기
23+
private void permutation(int index, String ids){
24+
//r만큼 다 뽑았을 경우
25+
if(index == bannedIds.length){
26+
String[] combination = ids.split("\\s");
27+
Arrays.sort(combination);
28+
29+
StringBuilder bannedCombination = new StringBuilder();
30+
for (String id : combination) {
31+
bannedCombination.append(id);
32+
}
33+
set.add(bannedCombination.toString());
34+
return;
35+
}
36+
37+
for(int i=0; i<userIds.length; i++){
38+
//이미 방문했거나 제재 목록과 형식 일치하지 않을 경우 패스
39+
if(visited[i] || !userIds[i].matches(bannedIds[index])){
40+
continue;
41+
}
42+
visited[i] = true;
43+
permutation(index+1, ids + " " + userIds[i]);
44+
visited[i] = false;
45+
}
46+
}
47+
48+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /