diff --git "a/src/main/kotlin/hyunsoo/65week/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" "b/src/main/kotlin/hyunsoo/65week/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" new file mode 100644 index 00000000..1037e5a1 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/65week/\352\264\204\355\230\270 \355\232\214\354\240\204\355\225\230\352\270\260.kt" @@ -0,0 +1,69 @@ +package hyunsoo.`65week` + +import java.util.* + /** + * + * <문제> + * [괄호 회전하기](https://school.programmers.co.kr/learn/courses/30/lessons/76502) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_괄호_희전하기` { + + private val opens = listOf('(', '[', '{') + + fun solution(s: String): Int { + var answer = 0 + + val target = s + s + + var start = 0 + repeat(s.length) { + if (target.slice(start until start + s.length).isAlright()) answer++ + start++ + } + + return answer + } + + private fun String.isAlright(): Boolean { + + val stack = Stack() + + this.forEachIndexed { index, ch -> + + if (ch in opens) { + stack.add(ch) + } + else { + + if (stack.isEmpty()) return false + + when (stack.peek()) { + '(' -> { + if (ch == ')') stack.pop() + else return false + } + '[' -> { + if (ch == ']') stack.pop() + else return false + } + '{' -> { + if (ch == '}') stack.pop() + else return false + } + } + } + } + + return stack.isEmpty() + + } +} + +fun main() { + 전현수_괄호_희전하기().solution("[](){}") +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/65week/\354\272\220\354\212\254 \353\224\224\355\216\234\354\212\244.kt" "b/src/main/kotlin/hyunsoo/65week/\354\272\220\354\212\254 \353\224\224\355\216\234\354\212\244.kt" new file mode 100644 index 00000000..e9fd36e5 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/65week/\354\272\220\354\212\254 \353\224\224\355\216\234\354\212\244.kt" @@ -0,0 +1,132 @@ +package hyunsoo.`65week` + +import java.util.LinkedList +import java.util.Queue + +/** + * + * <문제> + * [캐슬 디펜스](https://www.acmicpc.net/problem/17135) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_캐슬_디펜스` { + + private data class Position(val x: Int, val y: Int) + + private data class Bundle(val pos: Position, val range: Int) + + private var n = 0 + private var m = 0 + private var range = 0 + + private val board = mutableListOf>() + + private val pickedNumList = mutableListOf() + + var answer = 0 + + // 좌 상 우 + private val dirs = listOf( + Position(0, -1), + Position(-1, 0), + Position(0, 1), + ) + + fun solution() { + + readln().split(" ").map { it.toInt() }.apply { + n = this[0] + m = this[1] + range = this[2] + } + + repeat(n) { rowIndex -> + val row = readln().split(" ").map { it.toInt() } as MutableList + board.add(row) + } + + for (i in 0..m - 3) { + getCombinations(3, 0, i) + } + + println(answer) + } + + private fun getCombinations(depth: Int, cnt: Int, startIndex: Int) { + + if (depth == cnt) { + check(pickedNumList) + } + + for (index in startIndex until m) { + pickedNumList.add(index) + getCombinations(depth, cnt + 1, index + 1) + pickedNumList.removeLast() + } + + } + + private fun check(archersYList: List) { + + val curBoard = board.deepCopy() + + var curEliminatedCnt = 0 + + for (archerX in n - 1 downTo 0) { + + val targetSet = mutableSetOf() + + archersYList.forEach { curArcherY -> + + val queue: Queue = LinkedList() + + queue.add(Bundle(Position(archerX, curArcherY), 1)) + + while (queue.isNotEmpty()) { + + val (curPos, curRange) = queue.poll() + + if (curBoard[curPos.x][curPos.y] == 1) { + targetSet.add(Position(curPos.x, curPos.y)) + return@forEach + } + + if (curRange < range) { + dirs.forEach dir@{ + val nx = curPos.x + it.x + val ny = curPos.y + it.y + + + if (nx !in 0 until n || + ny !in 0 until m + ) return@dir + + queue.add(Bundle(Position(nx, ny), curRange + 1)) + } + } + } + } + + targetSet.forEach { + curBoard[it.x][it.y] = 0 + curEliminatedCnt++ + } + } + + if (answer < curEliminatedCnt) answer = curEliminatedCnt + + } + + private fun MutableList>.deepCopy() = + this.map { + it.toMutableList() + }.toMutableList() +} + +fun main() { + 전현수_캐슬_디펜스().solution() +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/65week/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\235.kt" "b/src/main/kotlin/hyunsoo/65week/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\235.kt" new file mode 100644 index 00000000..e2cdb013 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/65week/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\235.kt" @@ -0,0 +1,66 @@ +package hyunsoo.`65week` + +import java.util.* + +/** + * + * <문제> + * [후위 표기식](https://www.acmicpc.net/problem/1918) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_후위_표기식` { + + fun solution() { + + val s = readln() + val sb = StringBuilder() + val stack = Stack() + + s.forEach { ch -> + when (ch) { + '(' -> { + stack.push('(') + } + + '*', '/' -> { + while (stack.isNotEmpty()) { + if (stack.peek() == '*' || stack.peek() == '/') sb.append(stack.pop()) + else break + } + stack.push(ch) + } + + '+', '-' -> { + while (stack.isNotEmpty()) { + if (stack.peek() == '(') break + sb.append(stack.pop()) + } + stack.push(ch) + } + + ')' -> { + while (stack.isNotEmpty()) { + val fromStack = stack.pop() + if (fromStack == '(') break + sb.append(fromStack) + } + } + + else -> { + sb.append(ch) + } + } + } + + while (stack.isNotEmpty()) sb.append(stack.pop()) + println(sb) + } +} + +fun main() { + 전현수_후위_표기식().solution() +} \ No newline at end of file