From 00a7f0531d4bcea2b4f97ef9568b99fa92565115 Mon Sep 17 00:00:00 2001 From: seo-jio Date: Tue, 5 Sep 2023 00:26:24 +0900 Subject: [PATCH 1/2] =?UTF-8?q?solve(n=EC=A7=84=EC=88=98=EA=B2=8C=EC=9E=84?= =?UTF-8?q?,=20=ED=8C=8C=EC=9D=BC=EB=AA=85=EC=A0=95=EB=A0=AC):=20jio=5F230?= =?UTF-8?q?830?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\210\230\352\262\214\354\236\204.java" | 36 +++++++ ...\353\252\205\354\240\225\353\240\254.java" | 93 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 "jio/week26/n\354\247\204\354\210\230\352\262\214\354\236\204.java" create mode 100644 "jio/week26/\355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.java" diff --git "a/jio/week26/n\354\247\204\354\210\230\352\262\214\354\236\204.java" "b/jio/week26/n\354\247\204\354\210\230\352\262\214\354\236\204.java" new file mode 100644 index 0000000..04eea7c --- /dev/null +++ "b/jio/week26/n\354\247\204\354\210\230\352\262\214\354\236\204.java" @@ -0,0 +1,36 @@ +package week26; + +import java.util.*; + +class n진수게임 { + public String solution(int n, int t, int m, int p) { + StringBuilder answer = new StringBuilder(); + + char[] nums = makeTotalNums(n, t, m).toCharArray(); + + int cnt = 0; + int idx = 0; + + for(int i=0; i pque = new PriorityQueue((firstWord, secondWord) -> { + String first = firstWord.str; + String second = secondWord.str; + + String firstHead = findHead(first); + int firstNumber = Integer.parseInt(findNumber(first)); + + String secondHead = findHead(second); + int secondNumber = Integer.parseInt(findNumber(second)); + + if(!firstHead.equals(secondHead)) { + return firstHead.compareTo(secondHead); + } + + if(firstNumber != secondNumber) { + return Integer.compare(firstNumber, secondNumber); + } + + return Integer.compare(firstWord.idx, secondWord.idx); + }); + + for(int i=0; i= '0' && c <= '9'; + } + +} \ No newline at end of file From 84c73528ed33d599d440a4ef8049071e35d00084 Mon Sep 17 00:00:00 2001 From: seo-jio Date: Tue, 5 Sep 2023 00:28:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?solve(=EC=95=95=EC=B6=95,=20=ED=94=84?= =?UTF-8?q?=EB=A0=8C=EC=A6=884=EB=B8=94=EB=A1=9D):=20jio=5F230904?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "jio/week27/\354\225\225\354\266\225.java" | 68 +++++++++++ ...354\246\2104\353\270\224\353\241\235.java" | 112 ++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 "jio/week27/\354\225\225\354\266\225.java" create mode 100644 "jio/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" diff --git "a/jio/week27/\354\225\225\354\266\225.java" "b/jio/week27/\354\225\225\354\266\225.java" new file mode 100644 index 0000000..554ee51 --- /dev/null +++ "b/jio/week27/\354\225\225\354\266\225.java" @@ -0,0 +1,68 @@ +package week27; + +import java.io.*; +import java.util.*; + +class 압축 { + static Map words; + static List answer; + + public int[] solution(String msg) { + words = new HashMap<>(); + answer = new ArrayList<>(); + + makeDict(); + + char[] msgArr = msg.toCharArray(); + boolean isLast = false; + + for(int i=0; i i).toArray(); + } + + private static void makeDict() { // 사전 초기화 + char cur = 'A'; + int idx = 1; + while(true) { + words.put(String.valueOf(cur), idx); + if(cur == 'Z') { + break; + } + cur++; + idx++; + } + } +} \ No newline at end of file diff --git "a/jio/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" "b/jio/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" new file mode 100644 index 0000000..4da1006 --- /dev/null +++ "b/jio/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" @@ -0,0 +1,112 @@ +package week27; + +import java.util.*; + +class 프렌즈4블록 { + + static char[][] grid; + static boolean[][] bombGrid; + static int[] dx = {0, 0, 1, 1}; + static int[] dy = {0, 1, 1, 0}; + static int m, n; + + public int solution(int M, int N, String[] board) { + m = M; + n = N; + + grid = new char[m][n]; + + for(int x=0; x < board.length; x++) { + for(int y=0; y < board[x].length(); y++) { + grid[x][y] = board[x].charAt(y); + } + } + + int totalBomb = 0; + int cnt = 0; + + while(true) { + bombGrid = new boolean[m][n]; + int bombCnt = checkBomb(); + + if(bombCnt == 0) { // 더 이상 폭탄이 존재 하지 않는 경우 + break; + } + + totalBomb += bombCnt; + + bomb(); + + cnt++; + } + + + return totalBomb; + } + + private static int checkBomb() { // 폭탄 체크 + for(int x=0; x 'Z') { + continue; + } + + int cnt = 1; + + for(int dir=1; dir < 4; dir++) { + int nx = x + dx[dir]; + int ny = y + dy[dir]; + + if(grid[nx][ny] == cur) { + cnt++; + } + } + + if(cnt == 4) { + for(int dir=0; dir < 4; dir++) { + int nx = x + dx[dir]; + int ny = y + dy[dir]; + + bombGrid[nx][ny] = true; + } + } + } + } + + return countBomb(); + } + + private static int countBomb() { // 폭탄 개수 확인 + int count = 0; + + for(int x=0; x-1; x--) { + if(bombGrid[x][y]) { + continue; + } + + newGrid[idx][y] = grid[x][y]; + idx--; + } + } + + grid = newGrid; + } +} \ No newline at end of file