diff --git "a/hyeongu/week_26/n\354\247\204\354\210\230\352\262\214\354\236\204.java" "b/hyeongu/week_26/n\354\247\204\354\210\230\352\262\214\354\236\204.java" new file mode 100644 index 0000000..889950c --- /dev/null +++ "b/hyeongu/week_26/n\354\247\204\354\210\230\352\262\214\354\236\204.java" @@ -0,0 +1,23 @@ +class n진수게임 { + public String solution(int n, int t, int m, int p) { + StringBuilder sb = new StringBuilder(); + int maxSize = m * t; + + // 1부터 n진수로 바꿔서 계속 더함 + // m명의 사람이 t번씩 말하는 길이까지 구함 + for(int i = 0; sb.length() <= maxSize; i++){ + sb.append(Integer.toString(i, n)); + } + + // 왜 답을 대문자로 해놓는거야 귀찮게 + String total = sb.toString().toUpperCase(); + sb.setLength(0); + + // 튜브가 말할 숫자만 뽑아서 저장 + for(int i = p - 1; i < maxSize; i += m){ + sb.append(total.charAt(i)); + } + + return sb.toString(); + } +} \ No newline at end of file diff --git "a/hyeongu/week_26/\355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.java" "b/hyeongu/week_26/\355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.java" new file mode 100644 index 0000000..9515663 --- /dev/null +++ "b/hyeongu/week_26/\355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.java" @@ -0,0 +1,73 @@ +import java.util.*; + +class 파일명정렬 { + static List list = new ArrayList<>(); + + static class File implements Comparable{ + String fileName; // 전체 파일 이름 + String head; // head 부분 + int number; // index 부분 + int index; // 입력 순서 + + public File(String fileName, String head, int number) { + this.fileName = fileName; + this.head = head.toUpperCase(); + this.number = number; + this.index = list.size(); + } + + // 문제에 주어진 조건에 맞게 compare 규칙 정의 + public int compareTo(File f){ + if(this.head.equals(f.head)){ + if(this.number == f.number){ + return this.index - f.index; + } + return this.number - f.number; + } + return this.head.compareTo(f.head); + } + } + + public String[] solution(String[] files) { + String[] answer = new String[files.length]; + + for(String str : files){ + list.add(findHead(str)); + } + + Collections.sort(list); + + for(int i = 0; i < files.length; i++){ + answer[i] = list.get(i).fileName; + } + + return answer; + } + + // 주어진 string에서 숫자가 나오는 순간을 찾고 앞부분을 head로 저장 + public static File findHead(String str){ + for(int i = 0; i < str.length(); i++){ + char now = str.charAt(i); + + if(isNumber(now)){ + return new File(str, str.substring(0, i), findNumber(str, i)); + } + } + return null; + } + + // 이어진 숫자를 구해서 return + public static int findNumber(String str, int start){ + for(int i = start; i < str.length(); i++){ + char now = str.charAt(i); + if(!isNumber(now)){ + return Integer.parseInt(str.substring(start, i)); + } + } + return Integer.parseInt(str); + } + + public static boolean isNumber(char c){ + return c >= '0' && c <= '9'; + } +} \ No newline at end of file diff --git "a/hyeongu/week_27/\354\225\225\354\266\225.java" "b/hyeongu/week_27/\354\225\225\354\266\225.java" new file mode 100644 index 0000000..312a449 --- /dev/null +++ "b/hyeongu/week_27/\354\225\225\354\266\225.java" @@ -0,0 +1,37 @@ +import java.util.*; + +class 압축 { + public int[] solution(String msg) { + ArrayList al = new ArrayList<>(); + HashMap hm = new HashMap<>(); + int count = 1; + // A ~ Z 맵 초기화 + for(char c = 'A'; c <= 'Z'; c++) { + hm.put(c + "", count++); + } + + String tmp = msg; + while(tmp.length()>0) { + int i; + for(i = 1; i < tmp.length(); i++) { + // 사전에 없는 단어가 될 때까지 탐색 + // 없는 단어일 경우 리스트와 맵에 추가 + if(!hm.containsKey(tmp.substring(0, i + 1))) { + al.add(hm.get(tmp.substring(0, i))); + hm.put(tmp.substring(0, i + 1), count++); + break; + } + } + if(i == tmp.length()) { + al.add(hm.get(tmp)); + } + tmp = tmp.substring(i); + } + + int[] answer = new int[al.size()]; + for(int j = 0; j < al.size(); j++) { + answer[j] = al.get(j); + } + return answer; + } +} \ No newline at end of file diff --git "a/hyeongu/week_27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" "b/hyeongu/week_27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" new file mode 100644 index 0000000..be6d19c --- /dev/null +++ "b/hyeongu/week_27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" @@ -0,0 +1,55 @@ +import java.util.*; +class 프렌즈4블록 { + public int solution(int m, int n, String[] board) { + boolean[][] check = new boolean[n][m]; + int answer = 0; + boolean isBreak = true; + ArrayList[] arr = new ArrayList[n]; + + for(int i = 0; i < n; i++) { + arr[i] = new ArrayList(); + } + for(int i = m; i > 0; i--) { + for(int j = 0; j < n; j++) { + arr[j].add(board[i - 1].charAt(j)); + } + } + + // 아래에서부터 시작하는 ArrayList를 이용해 remove하면 자동으로 내려오게 구현 + while(isBreak){ + //삭제하는 블럭이 있을경우 true, 없는경우 while문 종료 + isBreak = false; + for(int i = 0; i < n - 1; i++) { + for(int j = 0; j < arr[i].size() - 1; j++) { + // 현재 칸 만큼 옆의 칸이 높이가 올라오지 않은 경우 + if(arr[i + 1].size() <= j + 1) { + break; + } + + // 사각형 모양으로 다 같으면 기록 + if(arr[i].get(j) == arr[i].get(j + 1)) { + if(arr[i + 1].get(j) == arr[i + 1].get(j + 1)&&arr[i].get(j) == arr[i + 1].get(j)) { + check[i][j] = true; + check[i][j + 1] = true; + check[i + 1][j] = true; + check[i + 1][j + 1] = true; + isBreak = true; + } + } + } + } + + // 기록된 블록을 위에서부터 제거 + for(int i = 0; i < n; i++) { + for(int j = arr[i].size() - 1; j >= 0; j--) { + if(check[i][j]) { + arr[i].remove(j); + answer++; + check[i][j] = false; + } + } + } + } + return answer; + } +} \ No newline at end of file