From 9fa0d41a6f0747c21b6d5a923325c8fcf9b87570 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 13 Nov 2022 19:47:36 +0900 Subject: [PATCH 1/5] =?UTF-8?q?solve:=20=ED=9B=84=EC=9C=84=20=ED=91=9C?= =?UTF-8?q?=EA=B8=B0=EC=8B=9D2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \355\221\234\352\270\260\354\213\2352.kt" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "src/main/kotlin/heejik/9week/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\2352.kt" diff --git "a/src/main/kotlin/heejik/9week/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\2352.kt" "b/src/main/kotlin/heejik/9week/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\2352.kt" new file mode 100644 index 00000000..02d11731 --- /dev/null +++ "b/src/main/kotlin/heejik/9week/\355\233\204\354\234\204 \355\221\234\352\270\260\354\213\2352.kt" @@ -0,0 +1,39 @@ +package heejik.`9week` + +class `후위 표기식2` { + + val operands = mutableListOf() + + fun solve() { + val n = readln().toInt() + var postfix = readln().chunked(1).toMutableList() + + repeat(n) { cnt -> + val num = readln() + postfix = postfix.map { + if (it.contains('A' + cnt)) num + else it + }.toMutableList() + } + + postfix.forEach { + if (it.toIntOrNull() != null) { + operands.add(it.toDouble()) + } else { + val a = operands.removeLast() + val b = operands.removeLast() + when (it.first()) { + '*' -> operands.add(b * a) + '+' -> operands.add(b + a) + '/' -> operands.add(b / a) + '-' -> operands.add(b - a) + } + } + } + println(String.format("%.2f", operands.first())) + } +} + +fun main() { + `후위 표기식2`().solve() +} \ No newline at end of file From cd61e0e67a8158aadefa9b594c43113a684e881a Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 13 Nov 2022 19:49:45 +0900 Subject: [PATCH 2/5] =?UTF-8?q?solve:=20=EB=B0=B0=EC=97=B4=20=EB=B3=B5?= =?UTF-8?q?=EC=9B=90=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...65\354\233\220\355\225\230\352\270\260.kt" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "src/main/kotlin/heejik/9week/\353\260\260\354\227\264 \353\263\265\354\233\220\355\225\230\352\270\260.kt" diff --git "a/src/main/kotlin/heejik/9week/\353\260\260\354\227\264 \353\263\265\354\233\220\355\225\230\352\270\260.kt" "b/src/main/kotlin/heejik/9week/\353\260\260\354\227\264 \353\263\265\354\233\220\355\225\230\352\270\260.kt" new file mode 100644 index 00000000..e0fa088a --- /dev/null +++ "b/src/main/kotlin/heejik/9week/\353\260\260\354\227\264 \353\263\265\354\233\220\355\225\230\352\270\260.kt" @@ -0,0 +1,38 @@ +package heejik.`9week` + +class `배열 복원하기` { + + fun solve() { + + val (h, w, x, y) = readln().split(' ').map { it.toInt() } + + val a = MutableList(h) { MutableList(w) { 0 } } + val b = mutableListOf>() + + repeat(h + x) { + b.add(readln().split(' ').map { it.toInt() }.toMutableList()) + } + + for (i in 0 until h) { + for (j in 0 until w) { + if (i >= x && j >= y) { + a[i][j] = b[i][j] - a[i-x][j-y] + } + else { + a[i][j] = b[i][j] + } + } + } + a.forEach { row -> + row.forEach { value -> + print("$value ") + } + println() + } + } +} + + +fun main() { + `배열 복원하기`().solve() +} \ No newline at end of file From 9e54c98141d33c1c293b5e56798bc2a7ae213487 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 13 Nov 2022 19:51:30 +0900 Subject: [PATCH 3/5] =?UTF-8?q?solve:=20=EB=8F=84=EC=96=B4=EB=A7=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\217\204\354\226\264\353\247\250.kt" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "src/main/kotlin/heejik/9week/\353\217\204\354\226\264\353\247\250.kt" diff --git "a/src/main/kotlin/heejik/9week/\353\217\204\354\226\264\353\247\250.kt" "b/src/main/kotlin/heejik/9week/\353\217\204\354\226\264\353\247\250.kt" new file mode 100644 index 00000000..6c212015 --- /dev/null +++ "b/src/main/kotlin/heejik/9week/\353\217\204\354\226\264\353\247\250.kt" @@ -0,0 +1,49 @@ +package heejik.`9week` + +class 도어맨 { + + + fun solve() { + + val x = readln().toInt() + var answer = 0 + val order = readln() + var wCount = 0 + var mCount = 0 + var isChanged = false + + kotlin.run { + order.forEachIndexed { index, _c -> + var c = _c + if (isChanged) { + isChanged = false + c = c.change() + } + if (c == 'W') { + if (wCount - mCount == x) { + if (index == order.length - 1 || order[index + 1] == 'W') return@run + isChanged = true + mCount++ + } else wCount++ + } else { + if (mCount - wCount == x) { + if (index == order.length - 1 || order[index + 1] == 'M') return@run + isChanged = true + wCount++ + } else mCount++ + } + answer++ + } + } + println(answer) + } + + private fun Char.change() = if (this == 'W') 'M' else 'W' + +} + +fun main() { + + 도어맨().solve() + +} \ No newline at end of file From 6f523a50ec07c2bbd2eea7f7cec1dfdc935055d1 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 13 Nov 2022 19:51:49 +0900 Subject: [PATCH 4/5] solve: Java vs C++ --- src/main/kotlin/heejik/9week/Java vs C++.kt | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/kotlin/heejik/9week/Java vs C++.kt diff --git a/src/main/kotlin/heejik/9week/Java vs C++.kt b/src/main/kotlin/heejik/9week/Java vs C++.kt new file mode 100644 index 00000000..250e2fa7 --- /dev/null +++ b/src/main/kotlin/heejik/9week/Java vs C++.kt @@ -0,0 +1,56 @@ +package heejik.`9week` + +class `Java vs C++` { + + data class JAVA(val variable: String) { + var cpp = "" + fun toCPP(): String { + variable.forEach { c -> + if (c.isUpperCase()) { + cpp += '_' + cpp += c.lowercaseChar() + } else { + cpp += c + } + } + return cpp + } + } + + data class CPP(val variable: String) { + var java = "" + fun toJava(): String { + var isUpper = false + variable.forEach { c -> + if (c == '_') { + isUpper = true + } else if (isUpper) { + java += c.uppercaseChar() + isUpper = false + } else { + java += c + } + } + return java + } + } + + fun solve() { + readln().run { + if (this.first().isLetter().not() || this.first().isLowerCase().not() || this.last() == '_' || this.contains("__")) { + println("Error!") + } else if (this.contains('_') && this.none { it.isUpperCase() }) { // CPP asd_asd + println(CPP(this).toJava()) + } else if (this.contains('_').not()){ // JAVA + println(JAVA(this).toCPP()) + } else { + println("Error!") + } + } + } +} + + +fun main() { + `Java vs C++`().solve() +} \ No newline at end of file From eca9b2846e67f58c1a58f60b17ff0d0ce577e09f Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Sun, 13 Nov 2022 19:52:04 +0900 Subject: [PATCH 5/5] =?UTF-8?q?solve:=20=201,=202,=203=20=EB=8D=94?= =?UTF-8?q?=ED=95=98=EA=B8=B0=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\215\224\355\225\230\352\270\260 4.kt" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "src/main/kotlin/heejik/9week/1, 2, 3 \353\215\224\355\225\230\352\270\260 4.kt" diff --git "a/src/main/kotlin/heejik/9week/1, 2, 3 \353\215\224\355\225\230\352\270\260 4.kt" "b/src/main/kotlin/heejik/9week/1, 2, 3 \353\215\224\355\225\230\352\270\260 4.kt" new file mode 100644 index 00000000..b3e2fae0 --- /dev/null +++ "b/src/main/kotlin/heejik/9week/1, 2, 3 \353\215\224\355\225\230\352\270\260 4.kt" @@ -0,0 +1,26 @@ +package heejik.`9week` + +// 답보풀: https://ku-hug.tistory.com/m/209 + +class `1, 2, 3 더하기 4` { + + fun solve() { + + val cnt = MutableList(10001) { 1 } + + for (i in 2..10000) { + cnt[i] += cnt[i-2] + } + + for (i in 3..10000) { + cnt[i] += cnt[i-3] + } + repeat(readln().toInt()) { + println(cnt[readln().toInt()]) + } + } +} + +fun main() { + `1, 2, 3 더하기 4`().solve() +} \ No newline at end of file