From 6473b0e0cf050a6860e648d7f36182c57f663376 Mon Sep 17 00:00:00 2001 From: bngsh Date: Sun, 2 Jun 2024 20:40:40 +0900 Subject: [PATCH] solve: 65week --- ...54\352\263\274\353\202\230\353\254\264.kt" | 29 ++++++++++++ ...4 \355\221\234\352\270\260\354\213\235.kt" | 46 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 "src/main/kotlin/byeonghee/week65/\354\202\254\352\263\274\353\202\230\353\254\264.kt" create mode 100644 "src/main/kotlin/byeonghee/week65/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\235.kt" diff --git "a/src/main/kotlin/byeonghee/week65/\354\202\254\352\263\274\353\202\230\353\254\264.kt" "b/src/main/kotlin/byeonghee/week65/\354\202\254\352\263\274\353\202\230\353\254\264.kt" new file mode 100644 index 00000000..41dc0e2a --- /dev/null +++ "b/src/main/kotlin/byeonghee/week65/\354\202\254\352\263\274\353\202\230\353\254\264.kt" @@ -0,0 +1,29 @@ +package byeonghee.week65 + +class 소병희_사과나무 { + companion object { + fun solve() = with(System.`in`.bufferedReader()) { + val n = readLine().toInt() + val trees = IntArray(n) + + var oneCnt = 0 //1 짜리 물뿌리개의 최소 필요개수 + var twoCnt = 0 // 2짜리 물뿌리개의 최대 필요개수 + var sum = 0 + + readLine().split(" ").forEachIndexed { i, v -> + trees[i] = v.toInt().also { + if (it % 2 == 1) oneCnt++ + if (it >= 2) twoCnt += it / 2 + sum += it + } + } + + if (sum % 3 > 0 || oneCnt > twoCnt) println("NO") + else println("YES") + } + } +} + +fun main() { + 소병희_사과나무.solve() +} \ No newline at end of file diff --git "a/src/main/kotlin/byeonghee/week65/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\235.kt" "b/src/main/kotlin/byeonghee/week65/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\235.kt" new file mode 100644 index 00000000..1e2dbddb --- /dev/null +++ "b/src/main/kotlin/byeonghee/week65/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\235.kt" @@ -0,0 +1,46 @@ +package byeonghee.week65 + +class 소병희_후위표기식 { + companion object { + val op = charArrayOf('+', '-', '*', '/', '(', ')') + + fun solve() = with(System.`in`.bufferedReader()) { + val st = ArrayDeque() + val sb = StringBuilder() + val pri = HashMap() + pri.put('+', 1) + pri.put('-', 1) + pri.put('*', 2) + pri.put('/', 2) + pri.put('(', 0) + pri.put(')', 0) + + readLine().forEach { i -> + if (i !in op) sb.append(i) + else if (i == '(') st.add(i) + else if (i == ')') { + while (st.isNotEmpty() && st.last() != '(') { + sb.append(st.removeLast()) + } + if (st.isNotEmpty()) st.removeLast() + } + else { + while(st.isNotEmpty() && pri[st.last()]!! >= pri[i]!!) { + sb.append(st.removeLast()) + } + st.add(i) + } + } + + while(st.isNotEmpty()) { + sb.append(st.removeLast()) + } + + println(sb) + } + } +} + +fun main() { + 소병희_후위표기식.solve() +} \ No newline at end of file