Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2021-03 1주차 #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions 2021 KAKAO BLIND RECRUITMENT/Solution_메뉴리뉴얼.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Solution {
static class Word implements Comparable<Word> {
String word;
int count;

public Word(String word, int count) {
this.word = word;
this.count = count;
}

@Override
public int compareTo(Word o) {
return Integer.compare(o.count, this.count);
}
}

static TreeSet<String> result = new TreeSet<>();
static PriorityQueue<Word>[] pqs;
static char[] chars;
static int idx;

public static void main(String[] args) throws Exception {
System.out.println(Arrays.toString(solution(new String[]{"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}, new int[]{2, 3, 4})));
}

public static String[] solution(String[] orders, int[] course) {
// 길이 및 오름차순 정렬
for (int i = 0; i < orders.length; i++) {
char[] charArr = orders[i].toCharArray();
Arrays.sort(charArr);
orders[i] = new String(charArr);
}
Arrays.sort(orders, Comparator.comparingInt(String::length));

pqs = new PriorityQueue[course.length];
for (int i = 0; i < pqs.length; i++) {
pqs[i] = new PriorityQueue<>();
}
// course 값의 개수 만큼 조합 시작
for (int i = 0; i < course.length; i++) {
for (int j = 0; j < orders.length; j++) {
chars = new char[course[i]];
combination(0, 0, course[i], orders[j], orders);
}
idx++;
}

for (int i = 0; i < idx; i++) {
int max = 0;
String str = "";
while (!pqs[i].isEmpty()) {
Word word = pqs[i].poll();
if (word.count == 1 || max > word.count) {
break;
}

if (max < word.count) { // 처음
str = word.word;
max = word.count;
result.add(word.word);
} else if (max == word.count && !str.equals(word.word)) { // 개수는 같으나 단어가 다르면
str = word.word;
result.add(word.word);
}
}
}

String[] answer = new String[result.size()];
int i = 0;
for (String s : result) {
answer[i++] = s;
}

return answer;
}

private static void combination(int cnt, int start, int r, String order, String[] orders) {
if (cnt == r) {
// 검색 시작
int count = 0;
for (int i = 0; i < orders.length; i++) {
boolean flag = true;
for (int j = 0; j < chars.length; j++) {
if (!orders[i].contains(chars[j] + "")) {
flag = false;
}
}
if (flag) {
count++;
}
}
pqs[idx].offer(new Word(new String(chars), count));
return;
}
for (int i = start; i < order.length(); i++) {
chars[cnt] = order.charAt(i);
combination(cnt + 1, i + 1, r, order, orders);
}
}
}
57 changes: 57 additions & 0 deletions 2021 KAKAO BLIND RECRUITMENT/Solution_신규아이디추천.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Solution {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

// 입력 출력
System.out.println(solution(br.readLine()));
}

public static String solution(String new_id) {
// 1단계
new_id = new_id.toLowerCase();

// 2단계
new_id = new_id.replaceAll("[^\\w.\\-_]", "");

// 3단계
new_id = new_id.replaceAll("\\.+", ".");

// 4단계
if (new_id.length() > 0 && new_id.charAt(0) == '.') {
StringBuilder sb = new StringBuilder(new_id);
sb.deleteCharAt(0);
new_id = sb.toString();
}
if (new_id.length() > 0 && new_id.charAt(new_id.length() - 1) == '.') {
StringBuilder sb = new StringBuilder(new_id);
sb.deleteCharAt(sb.length() - 1);
new_id = sb.toString();
}

// 5단계
if (new_id.length() == 0) {
new_id = "a";
}

// 6단계
if (new_id.length() >= 16) {
new_id = new_id.substring(0, 15);
}
if (new_id.charAt(new_id.length() - 1) == '.') {
StringBuilder sb = new StringBuilder(new_id);
sb.deleteCharAt(sb.length() - 1);
new_id = sb.toString();
}

// 7단계
while (new_id.length() <= 2) {
new_id += new_id.charAt(new_id.length() - 1);
}
return new_id;
}
}