diff --git "a/2021 KAKAO BLIND RECRUITMENT/Solution_\353\251\224\353\211\264\353\246\254\353\211\264\354\226\274.java" "b/2021 KAKAO BLIND RECRUITMENT/Solution_\353\251\224\353\211\264\353\246\254\353\211\264\354\226\274.java" new file mode 100644 index 0000000..ee84239 --- /dev/null +++ "b/2021 KAKAO BLIND RECRUITMENT/Solution_\353\251\224\353\211\264\353\246\254\353\211\264\354\226\274.java" @@ -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 { + 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 result = new TreeSet<>(); + static PriorityQueue[] 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); + } + } +} \ No newline at end of file diff --git "a/2021 KAKAO BLIND RECRUITMENT/Solution_\354\213\240\352\267\234\354\225\204\354\235\264\353\224\224\354\266\224\354\262\234.java" "b/2021 KAKAO BLIND RECRUITMENT/Solution_\354\213\240\352\267\234\354\225\204\354\235\264\353\224\224\354\266\224\354\262\234.java" new file mode 100644 index 0000000..2e28323 --- /dev/null +++ "b/2021 KAKAO BLIND RECRUITMENT/Solution_\354\213\240\352\267\234\354\225\204\354\235\264\353\224\224\354\266\224\354\262\234.java" @@ -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; + } +}