└── src ├── boj_10699 └── Kotlin.kt ├── boj_2557 ├── Kotlin.kt └── Main.java ├── boj_10926 └── Kotlin.kt ├── boj_15894 └── Kotlin.kt ├── boj_18108 └── Kotlin.kt ├── boj_24723 └── Kotlin.kt ├── boj_27323 └── Kotlin.kt ├── boj_11382 └── Kotlin.kt ├── boj_9655 └── Kotlin.kt ├── boj_9656 └── Kotlin.kt ├── boj_4999 └── Kotlin.kt ├── boj_2903 └── Kotlin.kt ├── boj_15439 └── Kotlin.kt ├── boj_14607 └── Kotlin.kt ├── boj_2490 └── Kotlin.kt ├── boj_27866 └── Kotlin.kt ├── boj_10171 ├── Kotlin.kt └── Main.java ├── boj_2752 └── Kotlin.kt ├── boj_24262 └── Kotlin.kt ├── boj_1000 ├── Kotlin.kt └── Main.java ├── boj_24263 └── Kotlin.kt ├── boj_2753 └── Kotlin.kt ├── boj_14495 └── Kotlin.kt ├── boj_3052 └── Kotlin.kt ├── boj_24264 └── Kotlin.kt ├── boj_11508 └── Kotlin.kt ├── boj_24266 └── Kotlin.kt ├── boj_2587 ├── Kotlin.kt └── Main.java ├── boj_2438 └── Kotlin.kt ├── boj_1758 └── Kotlin.kt ├── boj_2217 └── Kotlin.kt ├── boj_24265 └── Kotlin.kt ├── boj_2012 └── Kotlin.kt ├── boj_27433 └── Kotlin.kt ├── boj_15552 └── Kotlin.kt ├── boj_15964 └── Kotlin.kt ├── boj_10870 └── Kotlin.kt ├── boj_1919 └── Kotlin.kt ├── boj_10546 └── Kotlin.kt ├── boj_11867 └── Kotlin.kt ├── boj_1237 └── Main.java ├── boj_1436 └── Kotlin.kt ├── boj_17175 └── Kotlin.kt ├── boj_2420 └── Kotlin.kt ├── boj_2744 └── Kotlin.kt ├── boj_2941 └── Kotlin.kt ├── boj_10773 └── Kotlin.kt ├── boj_10808 └── Kotlin.kt ├── boj_15904 └── Kotlin.kt ├── boj_2754 └── Kotlin.kt ├── boj_3003 └── Kotlin.kt ├── boj_9498 └── Kotlin.kt ├── boj_10718 └── Main.java ├── boj_11931 └── Kotlin.kt ├── boj_13699 └── Kotlin.kt ├── boj_14606 └── Kotlin.kt ├── boj_2440 └── Kotlin.kt ├── boj_25304 └── Kotlin.kt ├── boj_10807 ├── Kotlin.kt └── Main.java ├── boj_2750 └── Kotlin.kt ├── boj_2577 └── Kotlin.kt ├── boj_24417 └── Kotlin.kt ├── boj_13301 └── Kotlin.kt ├── boj_2164 └── Kotlin.kt ├── boj_2231 └── Kotlin.kt ├── boj_3009 └── Kotlin.kt ├── boj_2441 └── Kotlin.kt ├── boj_25083 └── Kotlin.kt ├── boj_1475 └── Kotlin.kt ├── boj_15624 └── Kotlin.kt ├── boj_20365 └── Kotlin.kt ├── boj_25314 └── Kotlin.kt ├── boj_2443 └── Kotlin.kt ├── boj_2562 └── Kotlin.kt ├── boj_2439 └── Kotlin.kt ├── boj_7287 └── Main.java ├── boj_9086 └── Kotlin.kt ├── boj_18310 └── Kotlin.kt ├── boj_1769 └── Kotlin.kt ├── boj_2442 └── Kotlin.kt ├── boj_14215 └── Kotlin.kt ├── boj_24416 └── Kotlin.kt ├── boj_8394 └── Kotlin.kt ├── boj_24313 └── Kotlin.kt ├── boj_25192 └── Kotlin.kt ├── boj_9625 └── Kotlin.kt ├── boj_10162 └── Kotlin.kt ├── boj_2576 └── Kotlin.kt ├── boj_14425 └── Kotlin.kt ├── boj_20115 └── Kotlin.kt ├── boj_2075 └── Kotlin.kt ├── boj_3745 └── Main.java ├── boj_10804 └── Kotlin.kt ├── boj_21312 └── Kotlin.kt ├── boj_17212 └── Kotlin.kt ├── boj_9657 └── Kotlin.kt ├── boj_15829 └── Kotlin.kt ├── boj_2480 └── Kotlin.kt ├── boj_17626 └── Kotlin.kt ├── boj_20312 └── Kotlin.kt ├── boj_9658 └── Kotlin.kt ├── boj_10101 └── Kotlin.kt ├── boj_1085 └── Kotlin.kt ├── boj_10799 └── Kotlin.kt ├── boj_17608 └── Kotlin.kt ├── boj_2437 └── Kotlin.kt ├── boj_25305 └── Kotlin.kt ├── boj_2670 └── Kotlin.kt ├── boj_10093 └── Kotlin.kt ├── boj_20300 └── Kotlin.kt ├── boj_3986 └── Kotlin.kt ├── boj_11478 └── Kotlin.kt ├── boj_2558 └── Main.java ├── boj_1351 └── Kotlin.kt ├── boj_17271 └── Kotlin.kt ├── boj_5585 └── Kotlin.kt ├── boj_7785 └── Kotlin.kt ├── boj_1373 └── Kotlin.kt ├── boj_13164 └── Kotlin.kt ├── boj_13414 └── Kotlin.kt ├── boj_1793 └── Kotlin.kt ├── boj_18110 └── Kotlin.kt ├── boj_25099 └── Kotlin.kt ├── boj_2847 └── Kotlin.kt ├── boj_1259 └── Kotlin.kt ├── boj_3273 └── Kotlin.kt ├── boj_6198 └── Kotlin.kt ├── boj_1715 └── Kotlin.kt ├── boj_2295 └── Kotlin.kt ├── boj_2631 └── Kotlin.kt ├── boj_1541 └── Kotlin.kt ├── boj_2417 └── Kotlin.kt ├── boj_2743 └── Main.java ├── boj_15903 └── Kotlin.kt ├── boj_2293 └── Kotlin.kt ├── boj_10871 └── Kotlin.kt ├── boj_26069 └── Kotlin.kt ├── boj_9251 └── Kotlin.kt ├── boj_1267 └── Kotlin.kt ├── boj_1629 └── Kotlin.kt ├── boj_25418 └── Kotlin.kt ├── boj_10172 └── Main.java ├── boj_14916 └── Kotlin.kt ├── boj_23971 └── Kotlin.kt ├── boj_2446 └── Kotlin.kt ├── boj_2588 └── Kotlin.kt ├── boj_17219 └── Kotlin.kt ├── boj_2444 └── Kotlin.kt ├── boj_1026 └── Kotlin.kt ├── boj_5648 └── Kotlin.kt ├── boj_1417 └── Kotlin.kt ├── boj_16435 └── Kotlin.kt ├── boj_10610 └── Kotlin.kt ├── boj_1931 └── Kotlin.kt ├── boj_19532 └── Kotlin.kt ├── boj_14494 └── Kotlin.kt ├── boj_1439 └── Kotlin.kt ├── boj_17073 └── Kotlin.kt ├── boj_2475 └── Main.java ├── boj_10810 └── Kotlin.kt ├── boj_10813 └── Kotlin.kt ├── boj_2745 └── Kotlin.kt ├── boj_1269 └── Kotlin.kt ├── boj_16395 └── Kotlin.kt ├── boj_1543 └── Kotlin.kt ├── boj_4358 └── Kotlin.kt ├── boj_9093 └── Kotlin.kt ├── boj_2776 └── Kotlin.kt ├── boj_10869 └── Kotlin.kt ├── boj_14921 └── Kotlin.kt ├── boj_1927 └── Kotlin.kt ├── boj_11286 └── Kotlin.kt ├── boj_13144 └── Kotlin.kt ├── boj_20162 └── Kotlin.kt ├── boj_2512 └── Kotlin.kt ├── boj_1339 └── Kotlin.kt ├── boj_11279 └── Kotlin.kt ├── boj_15688 └── Kotlin.kt ├── boj_16172 └── Kotlin.kt ├── boj_18870 └── Kotlin.kt ├── boj_2720 └── Kotlin.kt ├── boj_3053 └── Main.java ├── boj_10872 └── Main.java ├── boj_1182 └── Kotlin.kt ├── boj_12015 └── Kotlin.kt ├── boj_14231 └── Kotlin.kt ├── boj_17216 └── Kotlin.kt ├── boj_20152 └── Kotlin.kt ├── boj_1449 └── Kotlin.kt ├── boj_1302 └── Kotlin.kt ├── boj_19941 └── Kotlin.kt ├── boj_2163 └── Main.java ├── boj_3046 └── Main.java ├── boj_4796 └── Kotlin.kt ├── boj_11005 └── Kotlin.kt ├── boj_2959 └── Main.java ├── boj_5565 └── Main.java ├── boj_11568 └── Kotlin.kt ├── boj_1158 └── Kotlin.kt ├── boj_18353 └── Kotlin.kt ├── boj_19621 └── Kotlin.kt ├── boj_19622 └── Kotlin.kt ├── boj_2230 └── Kotlin.kt ├── boj_2493 └── Kotlin.kt ├── boj_2812 └── Kotlin.kt ├── boj_2999 └── Kotlin.kt ├── boj_9063 └── Kotlin.kt ├── boj_11720 └── Main.java ├── boj_13300 └── Kotlin.kt ├── boj_2445 └── Kotlin.kt ├── boj_25214 └── Kotlin.kt ├── boj_9375 └── Kotlin.kt ├── boj_2914 └── Main.java ├── boj_22971 └── Kotlin.kt ├── boj_25706 └── Kotlin.kt ├── boj_27446 └── Kotlin.kt ├── boj_5338 └── Main.java ├── boj_2741 └── Main.java ├── boj_5598 └── Main.java ├── boj_10987 └── Main.java ├── boj_12789 └── Kotlin.kt ├── boj_5086 └── Kotlin.kt ├── boj_15651 └── Kotlin.kt ├── boj_2902 └── Main.java ├── boj_13975 └── Kotlin.kt ├── boj_17298 └── Kotlin.kt ├── boj_2921 └── Main.java ├── boj_10816 └── Kotlin.kt ├── boj_2156 └── Kotlin.kt ├── boj_9012 └── Kotlin.kt ├── boj_10811 └── Kotlin.kt ├── boj_1477 └── Kotlin.kt ├── boj_10822 └── Main.java ├── boj_11023 └── Main.java ├── boj_4097 └── Kotlin.kt ├── boj_10757 └── Main.java ├── boj_11652 └── Kotlin.kt ├── boj_11718 └── Main.java ├── boj_13305 └── Kotlin.kt ├── boj_2003 └── Kotlin.kt ├── boj_2010 └── Main.java ├── boj_11719 └── Main.java ├── boj_2870 └── Kotlin.kt ├── boj_9935 └── Kotlin.kt ├── boj_15652 └── Kotlin.kt ├── boj_11729 └── Kotlin.kt ├── boj_15650 └── Kotlin.kt ├── boj_19583 └── Kotlin.kt ├── boj_13277 └── Main.java ├── boj_2738 └── Kotlin.kt ├── boj_2828 └── Kotlin.kt ├── boj_5347 └── Kotlin.kt ├── boj_8320 └── Main.java ├── boj_1152 └── Main.java ├── boj_11659 └── Kotlin.kt ├── boj_24511 └── Kotlin.kt ├── boj_9663 └── Kotlin.kt ├── boj_10988 └── Main.java ├── boj_1620 └── Kotlin.kt ├── boj_21314 └── Kotlin.kt ├── boj_15489 └── Kotlin.kt ├── boj_20922 └── Kotlin.kt ├── boj_2909 └── Main.java ├── boj_5532 └── Main.java ├── boj_5554 └── Main.java ├── boj_10211 └── Kotlin.kt ├── boj_10827 └── Main.java ├── boj_1655 └── Kotlin.kt ├── boj_1822 └── Kotlin.kt ├── boj_2033 └── Main.java ├── boj_2869 └── Main.java ├── boj_1021 └── Kotlin.kt ├── boj_15990 └── Kotlin.kt ├── boj_2467 └── Kotlin.kt ├── boj_2501 └── Main.java ├── boj_16401 └── Kotlin.kt ├── boj_2805 └── Kotlin.kt ├── boj_1003 └── Kotlin.kt ├── boj_1644 └── Kotlin.kt ├── boj_10156 └── Main.java ├── boj_22857 └── Kotlin.kt ├── boj_11328 └── Kotlin.kt ├── boj_2935 └── Main.java ├── boj_5639 └── Kotlin.kt ├── boj_9546 └── Main.java ├── boj_11094 └── Main.java ├── boj_1747 └── Kotlin.kt ├── boj_10039 └── Main.java ├── boj_10797 └── Main.java ├── boj_14430 └── Kotlin.kt ├── boj_1535 └── Kotlin.kt ├── boj_20920 └── Kotlin.kt ├── boj_7567 └── Main.java ├── boj_2294 └── Kotlin.kt ├── boj_2986 └── Main.java ├── boj_11497 └── Kotlin.kt ├── boj_10707 └── Main.java ├── boj_1100 └── Main.java ├── boj_11047 └── Kotlin.kt ├── boj_16916 └── Kotlin.kt ├── boj_2965 └── Main.java ├── boj_4150 └── Main.java ├── boj_11721 └── Main.java ├── boj_1789 └── Main.java ├── boj_2355 └── Main.java ├── boj_2668 └── Kotlin.kt ├── boj_15988 └── Kotlin.kt ├── boj_10951 └── Main.java ├── boj_11726 └── Main.java ├── boj_1712 └── Main.java ├── boj_11653 └── Main.java ├── boj_1806 └── Kotlin.kt └── boj_2526 └── Main.java /src/boj_10699/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10699 2 | 3 | fun main() = print("2024-01-06") 4 | -------------------------------------------------------------------------------- /src/boj_2557/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2557 2 | 3 | fun main() = print("Hello World!") 4 | -------------------------------------------------------------------------------- /src/boj_10926/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10926 2 | 3 | fun main() = println("${readln()}??!") 4 | -------------------------------------------------------------------------------- /src/boj_15894/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15894 2 | 3 | fun main() = println(readln().toInt() * 4L) 4 | -------------------------------------------------------------------------------- /src/boj_18108/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_18108 2 | 3 | fun main() = println(readln().toInt() - 543) 4 | -------------------------------------------------------------------------------- /src/boj_24723/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24723 2 | 3 | fun main() = println(1 shl readln().toInt()) 4 | -------------------------------------------------------------------------------- /src/boj_27323/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_27323 2 | 3 | fun main() = println(readln().toInt() * readln().toInt()) 4 | -------------------------------------------------------------------------------- /src/boj_11382/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11382 2 | 3 | fun main() = println(readln().split(" ").sumOf { it.toLong() }) 4 | -------------------------------------------------------------------------------- /src/boj_9655/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9655 2 | 3 | fun main() = print(if (readln().toInt() and 1 == 1) "SK" else "CY") 4 | -------------------------------------------------------------------------------- /src/boj_9656/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9656 2 | 3 | fun main() = print(if (readln().toInt() and 1 == 0) "SK" else "CY") 4 | -------------------------------------------------------------------------------- /src/boj_4999/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_4999 2 | 3 | fun main() = print(if (readln().length < readln().length) "no" else "go") 4 | -------------------------------------------------------------------------------- /src/boj_2903/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2903 2 | 3 | fun main() = println(((2L shl readln().toInt() - 1) + 1).run { this * this }) 4 | -------------------------------------------------------------------------------- /src/boj_15439/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15439 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | println(n * (n - 1)) 7 | } 8 | -------------------------------------------------------------------------------- /src/boj_14607/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14607 2 | 3 | fun main() { 4 | val n = readln().toLong() 5 | 6 | print(n * (n - 1) shr 1) 7 | } 8 | -------------------------------------------------------------------------------- /src/boj_2490/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2490 2 | 3 | fun main() = repeat(times = 3) { 4 | println('A' + (readln().count { it == '0' } + 4) % 5) 5 | } 6 | -------------------------------------------------------------------------------- /src/boj_27866/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_27866 2 | 3 | fun main() { 4 | val s = readln() 5 | val i = readln().toInt() 6 | 7 | println(s[i - 1]) 8 | } 9 | -------------------------------------------------------------------------------- /src/boj_10171/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10171 2 | 3 | fun main() = print( 4 | """ 5 | \ /\ 6 | ) ( ') 7 | ( / ) 8 | \(__)| 9 | """.trimIndent() 10 | ) 11 | -------------------------------------------------------------------------------- /src/boj_2752/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2752 2 | 3 | fun main() = print( 4 | readln() 5 | .split(" ") 6 | .sortedBy { it.toInt() } 7 | .joinToString(separator = " ") 8 | ) 9 | -------------------------------------------------------------------------------- /src/boj_24262/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24262 2 | 3 | fun main() { 4 | val result = buildString { 5 | appendLine(value = 1) 6 | append(0) 7 | } 8 | 9 | println(result) 10 | } 11 | -------------------------------------------------------------------------------- /src/boj_1000/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1000 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | print(st.nextToken().toByte() + st.nextToken().toByte()) 8 | } 9 | -------------------------------------------------------------------------------- /src/boj_24263/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24263 2 | 3 | fun main() { 4 | val result = buildString { 5 | appendLine(readln().toInt()) 6 | append(1) 7 | } 8 | 9 | println(result) 10 | } 11 | -------------------------------------------------------------------------------- /src/boj_2753/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2753 2 | 3 | fun main() { 4 | val year = readln().toInt() 5 | val isLeapYear = if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) 1 else 0 6 | print(isLeapYear) 7 | } 8 | -------------------------------------------------------------------------------- /src/boj_14495/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14495 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val f = LongArray(size = 117) { 1L } 7 | for (i in 4..n) f[i] = f[i - 1] + f[i - 3] 8 | 9 | print(f[n]) 10 | } 11 | -------------------------------------------------------------------------------- /src/boj_3052/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_3052 2 | 3 | fun main() { 4 | val remains = mutableSetOf() 5 | repeat(times = 10) { 6 | remains.add(readln().toInt() % 42) 7 | } 8 | 9 | println(remains.size) 10 | } 11 | -------------------------------------------------------------------------------- /src/boj_24264/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24264 2 | 3 | fun main() { 4 | val result = buildString { 5 | val n = readln().toLong() 6 | appendLine(value = n * n) 7 | append(2) 8 | } 9 | 10 | println(result) 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_11508/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11508 2 | 3 | fun main() = IntArray(readln().toInt()) { readln().toInt() } 4 | .apply { sortDescending() } 5 | .foldIndexed(initial = 0) { i, acc, cost -> acc + if (i % 3 == 2) 0 else cost } 6 | .run(::print) 7 | -------------------------------------------------------------------------------- /src/boj_24266/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24266 2 | 3 | fun main() { 4 | val result = buildString { 5 | val n = readln().toLong() 6 | appendLine(value = n * n * n) 7 | append(3) 8 | } 9 | 10 | println(result) 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_2587/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2587 2 | 3 | fun main() { 4 | val nums = ByteArray(size = 5) 5 | repeat(times = 5) { nums[it] = readln().toByte() } 6 | nums.sort() 7 | 8 | print("${nums.average().toInt()}\n${nums[2]}") 9 | } 10 | -------------------------------------------------------------------------------- /src/boj_2438/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2438 2 | 3 | fun main() = System.out.bufferedWriter().use { bw -> 4 | repeat(readln().toInt()) { 5 | repeat(times = it + 1) { bw.write("*") } 6 | bw.write("\n") 7 | } 8 | bw.flush() 9 | } 10 | -------------------------------------------------------------------------------- /src/boj_1758/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1758 2 | 3 | fun main() = IntArray(readln().toInt()) { readln().toInt() } 4 | .apply { sortDescending() } 5 | .foldIndexed(initial = 0L) { i, acc, tip -> acc + (tip - i).coerceAtLeast(minimumValue = 0) } 6 | .run(::print) 7 | -------------------------------------------------------------------------------- /src/boj_2217/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2217 2 | 3 | fun main() = IntArray(readln().toInt()) { readln().toInt() } 4 | .apply { sortDescending() } 5 | .foldIndexed(initial = 0) { i, maxWeight, weight -> maxOf(maxWeight, b = (i + 1) * weight) } 6 | .run(::print) 7 | -------------------------------------------------------------------------------- /src/boj_24265/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24265 2 | 3 | fun main() { 4 | val result = buildString { 5 | val n = readln().toLong() 6 | appendLine(value = n * (n - 1) shr 1) 7 | append(2) 8 | } 9 | 10 | println(result) 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_2012/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2012 2 | 3 | import kotlin.math.abs 4 | 5 | fun main() = IntArray(readln().toInt()) { readln().toInt() } 6 | .apply { sort() } 7 | .foldIndexed(initial = 0L) { i, acc, rank -> acc + abs(n = i + 1 - rank) } 8 | .run(::print) 9 | -------------------------------------------------------------------------------- /src/boj_27433/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_27433 2 | 3 | fun main() { 4 | val n = readln().toLong() 5 | 6 | println(factorial(n)) 7 | } 8 | 9 | fun factorial(n: Long): Long { 10 | if (n <= 1) return 1 11 | 12 | return n * factorial(n = n - 1) 13 | } 14 | -------------------------------------------------------------------------------- /src/boj_15552/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15552 2 | 3 | fun main() = System.out.bufferedWriter().use { bw -> 4 | repeat(readln().toInt()) { 5 | bw.write(readln().split(" ").sumOf { it.toInt() }.toString()) 6 | bw.write("\n") 7 | } 8 | bw.flush() 9 | } 10 | -------------------------------------------------------------------------------- /src/boj_15964/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15964 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val a = st.nextToken().toLong() 8 | val b = st.nextToken().toLong() 9 | 10 | print(a * a - b * b) 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_10870/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10870 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | println(fibonacci(n)) 7 | } 8 | 9 | fun fibonacci(n: Int): Int { 10 | if (n <= 1) return n 11 | 12 | return fibonacci(n = n - 2) + fibonacci(n = n - 1) 13 | } 14 | -------------------------------------------------------------------------------- /src/boj_1919/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1919 2 | 3 | import kotlin.math.abs 4 | 5 | fun main() { 6 | val counts = IntArray(size = 26) 7 | readln().forEach { ++counts[it - 'a'] } 8 | readln().forEach { --counts[it - 'a'] } 9 | 10 | print(counts.sumOf(::abs)) 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_10546/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10546 2 | 3 | fun main() { 4 | val set = hashSetOf() 5 | repeat(times = (readln().toInt() shl 1) - 1) { 6 | val name = readln() 7 | if (!set.remove(name)) set.add(name) 8 | } 9 | 10 | print(set.first()) 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_11867/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11867 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | print(if (n and m and 1 == 1) "B" else "A") 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_1237/Main.java: -------------------------------------------------------------------------------- 1 | package boj_1237; 2 | 3 | /** 4 | * 백준 온라인 저지 1237번 (정ㅋ벅ㅋ) 문제풀이 5 | * 6 | * @see https://www.acmicpc.net/problem/1237 7 | * @author devetude 8 | */ 9 | public class Main { 10 | public static void main(String args[]) { 11 | System.out.println("문제의 정답"); 12 | } 13 | } -------------------------------------------------------------------------------- /src/boj_1436/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1436 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | var title = 666 7 | var count = 1 8 | while (count < n) { 9 | ++title 10 | if ("666" in title.toString()) ++count 11 | } 12 | 13 | println(title) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_17175/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17175 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val times = IntArray(size = n + 1) { 1 } 7 | for (i in 2..n) { 8 | times[i] = (times[i - 2] + times[i - 1] + 1) % 1_000_000_007 9 | } 10 | 11 | print(times[n]) 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_2420/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2420 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.abs 5 | 6 | fun main() { 7 | val st = StringTokenizer(readln()) 8 | val n = st.nextToken().toLong() 9 | val m = st.nextToken().toLong() 10 | 11 | print(abs(n = n - m)) 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_2557/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2557; 2 | 3 | /** 4 | * 백준 온라인 저지 2557번 (Hello World) 문제풀이 5 | * 6 | * @see https://www.acmicpc.net/problem/2557 7 | * @author devetude 8 | */ 9 | public class Main { 10 | public static void main(String args[]) { 11 | System.out.println("Hello World!"); 12 | } 13 | } -------------------------------------------------------------------------------- /src/boj_2744/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2744 2 | 3 | fun main() { 4 | val gap = 'a' - 'A' 5 | val result = buildString { 6 | readln().asSequence() 7 | .map { if (it in 'A'..'Z') it + gap else it - gap } 8 | .forEach(::append) 9 | } 10 | 11 | print(result) 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_2941/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2941 2 | 3 | fun main() { 4 | var s = readln() 5 | val croatiaAlphabets = setOf("c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z=") 6 | 7 | croatiaAlphabets.forEach { 8 | s = s.replace(it, newValue = "*") 9 | } 10 | 11 | println(s.length) 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_10773/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10773 2 | 3 | import java.util.Stack 4 | 5 | fun main() { 6 | val stack = Stack() 7 | repeat(readln().toInt()) { 8 | val num = readln().toInt() 9 | if (0 < num) stack.push(num) else stack.pop() 10 | } 11 | 12 | print(stack.sum()) 13 | } 14 | -------------------------------------------------------------------------------- /src/boj_10808/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10808 2 | 3 | fun main() { 4 | val frequencyOf = IntArray(size = 26) 5 | readln().forEach { ++frequencyOf[it - 'a'] } 6 | 7 | System.out.bufferedWriter().use { 8 | it.write(frequencyOf.joinToString(separator = " ")) 9 | it.flush() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/boj_15904/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15904 2 | 3 | fun main() { 4 | val str = readln() 5 | 6 | var i = 0 7 | str.forEach { char -> 8 | if (char == "UCPC"[i]) { 9 | if (4 == ++i) return println("I love UCPC") 10 | } 11 | } 12 | 13 | println("I hate UCPC") 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_2754/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2754 2 | 3 | fun main() { 4 | val grade = readln() 5 | if (grade == "F") return print("0.0") 6 | 7 | val score = 4.0 - (grade[0] - 'A') + when (grade[1]) { 8 | '+' -> 0.3 9 | '0' -> 0.0 10 | else -> -0.3 11 | } 12 | print(score) 13 | } 14 | -------------------------------------------------------------------------------- /src/boj_3003/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_3003 2 | 3 | fun main() { 4 | val correctCounts = listOf(1, 1, 2, 2, 2, 8) 5 | 6 | val result = readln() 7 | .split(" ") 8 | .mapIndexed { i, s -> correctCounts[i] - s.toInt() } 9 | .joinToString(separator = " ") 10 | 11 | println(result) 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_9498/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9498 2 | 3 | fun main() { 4 | val score = readln().toByte() 5 | 6 | val grade = when { 7 | score < 60 -> 'F' 8 | score < 70 -> 'D' 9 | score < 80 -> 'C' 10 | score < 90 -> 'B' 11 | else -> 'A' 12 | } 13 | print(grade) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_10718/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10718; 2 | 3 | /** 4 | * 백준 온라인 저지 10718번 (We love kriii) 문제풀이 5 | * 6 | * @see https://www.acmicpc.net/problem/10718 7 | * @author devetude 8 | */ 9 | public class Main { 10 | public static void main(String args[]) { 11 | System.out.println("강한친구 대한육군\n강한친구 대한육군"); 12 | } 13 | } -------------------------------------------------------------------------------- /src/boj_11931/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11931 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | val arr = IntArray(n) { readln().toInt() } 6 | arr.sortDescending() 7 | 8 | System.out.bufferedWriter().use { 9 | it.write(arr.joinToString(separator = "\n")) 10 | it.flush() 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_13699/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13699 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val t = LongArray(size = n + 1) 7 | t[0] = 1 8 | for (i in 1..n) { 9 | for (j in 0.. 7 | repeat(n) { row -> 8 | repeat(times = n - row) { bw.write("*") } 9 | bw.write("\n") 10 | } 11 | bw.flush() 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/boj_25304/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25304 2 | 3 | fun main() { 4 | var sum = readln().toInt() 5 | 6 | repeat(readln().toInt()) { 7 | val (price, quantity) = readln().split(" ").map { it.toInt() } 8 | sum -= price * quantity 9 | } 10 | 11 | println(if (sum == 0) "Yes" else "No") 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_10807/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10807 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val st = StringTokenizer(readln()) 8 | val v = readln() 9 | 10 | var count = 0 11 | repeat(n) { if (st.nextToken() == v) ++count } 12 | 13 | print(count) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_2750/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2750 2 | 3 | fun main() { 4 | val result = ShortArray(readln().toInt()) { readln().toShort() } 5 | .apply { sort() } 6 | .joinToString(separator = "\n") 7 | 8 | System.out.bufferedWriter().use { 9 | it.write(result) 10 | it.flush() 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_2577/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2577 2 | 3 | fun main() { 4 | val a = readln().toInt() 5 | val b = readln().toInt() 6 | val c = readln().toInt() 7 | 8 | val count = IntArray(size = 10) 9 | (a * b * c).toString().forEach { ++count[it - '0'] } 10 | 11 | print(count.joinToString(separator = "\n")) 12 | } 13 | -------------------------------------------------------------------------------- /src/boj_24417/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24417 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val arr = IntArray(size = 3) { it } 7 | for (i in 2..n) { 8 | arr[2] = (arr[0] + arr[1]) % 1_000_000_007 9 | arr[0] = arr[1] 10 | arr[1] = arr[2] 11 | } 12 | 13 | print("${arr[2]} ${n - 2}") 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_13301/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13301 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val sides = LongArray(size = n + 1) 7 | sides[1] = 1 8 | for (i in 2..n) { 9 | sides[i] = sides[i - 2] + sides[i - 1] 10 | } 11 | val perimeter = (sides[n - 1] shl 1) + (sides[n] shl 2) 12 | 13 | print(perimeter) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_2164/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2164 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val arr = IntArray(size = (n shl 1) - 1) { it + 1 } 7 | var first = 0 8 | var last = n - 1 9 | 10 | while (first < last) { 11 | ++first 12 | arr[++last] = arr[first++] 13 | } 14 | 15 | print(arr[first]) 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_2231/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2231 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | var num = 1 7 | while (num < n) { 8 | val decompositionSum = num + num.toString().sumOf(Character::getNumericValue) 9 | if (decompositionSum == n) return println(num) 10 | ++num 11 | } 12 | 13 | println(0) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_3009/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_3009 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var x = 0 7 | var y = 0 8 | repeat(times = 3) { 9 | val st = StringTokenizer(readln()) 10 | x = x xor st.nextToken().toInt() 11 | y = y xor st.nextToken().toInt() 12 | } 13 | 14 | println("$x $y") 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_2441/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2441 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | repeat(n) { row -> 8 | repeat(row) { bw.write(" ") } 9 | repeat(times = n - row) { bw.write("*") } 10 | bw.write("\n") 11 | } 12 | bw.flush() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_25083/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25083 2 | 3 | fun main() { 4 | val result = """ 5 | ,r'"7 6 | r`-_ ,' ,/ 7 | \. ". L_r' 8 | `~\/ 9 | | 10 | | 11 | """.trimIndent() 12 | 13 | System.out.bufferedWriter().use { 14 | it.write(result) 15 | it.flush() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/boj_1475/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1475 2 | 3 | fun main() { 4 | val counts = IntArray(size = 10) 5 | readln().forEach { ++counts[it - '0'] } 6 | val minSetExceptFor6N9 = counts.filterIndexed { num, _ -> num != 6 && num != 9 }.max() 7 | val minSetFor6N9 = counts[6] + counts[9] + 1 shr 1 8 | 9 | print(minSetFor6N9.coerceAtLeast(minSetExceptFor6N9)) 10 | } 11 | -------------------------------------------------------------------------------- /src/boj_15624/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15624 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val arr = IntArray(size = 3) { it } 7 | if (n < 2) return print(arr[n]) 8 | 9 | for (i in 2..n) { 10 | arr[2] = (arr[0] + arr[1]) % 1_000_000_007 11 | arr[0] = arr[1] 12 | arr[1] = arr[2] 13 | } 14 | 15 | print(arr[2]) 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_20365/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_20365 2 | 3 | fun main() { 4 | readln() 5 | var prev = ' ' 6 | var r = 0 7 | var b = 0 8 | readln().forEach { 9 | if (it != prev) if (it == 'R') ++r else ++b 10 | prev = it 11 | } 12 | 13 | val minCount = maxOf(r, b).coerceAtMost(maximumValue = 1) + minOf(r, b) 14 | print(minCount) 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_25314/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25314 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val times = n / 4 7 | val result = buildString { 8 | repeat(times) { append("long ") } 9 | appendLine(value = "int") 10 | } 11 | 12 | System.out.bufferedWriter().use { 13 | it.write(result) 14 | it.flush() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_2443/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2443 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | repeat(n) { row -> 8 | repeat(row) { bw.write(" ") } 9 | repeat(times = (n - row shl 1) - 1) { bw.write("*") } 10 | bw.write("\n") 11 | } 12 | bw.flush() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_2562/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2562 2 | 3 | fun main() { 4 | var maxValue = readln().toByte() 5 | var maxValueNum = 1 6 | repeat(times = 8) { 7 | val value = readln().toByte() 8 | if (value < maxValue) return@repeat 9 | 10 | maxValue = value 11 | maxValueNum = it + 2 12 | } 13 | 14 | print("$maxValue\n$maxValueNum") 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_2439/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2439 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | repeat(n) { row -> 8 | repeat(times = n - row - 1) { bw.write(" ") } 9 | repeat(times = row + 1) { bw.write("*") } 10 | bw.write("\n") 11 | } 12 | bw.flush() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_7287/Main.java: -------------------------------------------------------------------------------- 1 | package boj_7287; 2 | 3 | /** 4 | * 백준 온라인 저지 7287번 (등록) 문제풀이 5 | * 6 | * @see https://www.acmicpc.net/problem/7287 7 | * @author devetude 8 | */ 9 | public class Main { 10 | public static void main(String args[]) { 11 | StringBuilder sb = new StringBuilder(); 12 | sb.append(164).append("\ndevetude"); 13 | System.out.println(sb.toString()); 14 | } 15 | } -------------------------------------------------------------------------------- /src/boj_9086/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9086 2 | 3 | fun main() { 4 | val result = buildString { 5 | repeat(readln().toInt()) { 6 | val s = readln() 7 | append(s.first(), s.last()) 8 | appendLine() 9 | } 10 | } 11 | 12 | System.out.bufferedWriter().use { 13 | it.write(result) 14 | it.flush() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_18310/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_18310 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val st = StringTokenizer(readln()) 8 | val x = IntArray(n) 9 | repeat(n) { x[it] = st.nextToken().toInt() } 10 | 11 | if (x.size == 1) return println(x.first()) 12 | 13 | x.sort() 14 | 15 | println(x[(n - 1) shr 1]) 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_1769/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1769 2 | 3 | fun main() { 4 | var x = readln() 5 | 6 | var count = 0 7 | while (1 < x.length) { 8 | ++count 9 | val y = x.sumOf { it - '0' } 10 | x = y.toString() 11 | } 12 | val result = when (x) { 13 | "3", "6", "9" -> "YES" 14 | else -> "NO" 15 | } 16 | 17 | print("$count\n$result") 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_2442/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2442 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | repeat(n) { row -> 8 | repeat(times = n - row - 1) { bw.write(" ") } 9 | repeat(times = (row shl 1) + 1) { bw.write("*") } 10 | bw.write("\n") 11 | } 12 | bw.flush() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_14215/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14215 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val sides = buildList { 7 | val st = StringTokenizer(readln()) 8 | repeat(times = 3) { add(st.nextToken().toInt()) } 9 | }.sorted() 10 | 11 | val maxSide = (sides[0] + sides[1] - 1).coerceAtMost(sides[2]) 12 | 13 | println(sides[0] + sides[1] + maxSide) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_24416/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24416 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val fibonacci = IntArray(size = n + 1) 7 | fibonacci[1] = 1 8 | fibonacci[2] = 1 9 | for (i in 3..n) { 10 | fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1] 11 | } 12 | val result = buildString { append(fibonacci[n], " ", n - 2) } 13 | 14 | println(result) 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_8394/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_8394 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val arr = IntArray(size = 3) 7 | arr[1] = 2 8 | arr[2] = 3 9 | 10 | if (n < 4) return print(arr[n - 1]) 11 | 12 | for (i in 4..n) { 13 | arr[0] = arr[1] 14 | arr[1] = arr[2] 15 | arr[2] = (arr[1] + arr[0]) % 10 16 | } 17 | 18 | print(arr[2]) 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_24313/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24313 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val a1 = st.nextToken().toInt() 8 | val a0 = st.nextToken().toInt() 9 | val c = readln().toInt() 10 | val n0 = readln().toInt() 11 | 12 | val result = if (a1 * n0 + a0 <= c * n0 && a1 <= c) 1 else 0 13 | 14 | println(result) 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_25192/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25192 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | var count = 0 7 | val set = HashSet() 8 | repeat(n) { 9 | val message = readln() 10 | if (message == "ENTER") { 11 | set.clear() 12 | } else { 13 | if (set.add(message)) ++count 14 | } 15 | } 16 | 17 | println(count) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_9625/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9625 2 | 3 | fun main() { 4 | val k = readln().toInt() 5 | 6 | val aCounts = IntArray(size = k + 1) 7 | val bCounts = IntArray(size = k + 1) 8 | bCounts[1] = 1 9 | 10 | for (i in 2..k) { 11 | aCounts[i] = bCounts[i - 1] 12 | bCounts[i] = bCounts[i - 2] + bCounts[i - 1] 13 | } 14 | 15 | print("${aCounts[k]} ${bCounts[k]}") 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_10162/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10162 2 | 3 | val SECS = arrayOf(300, 60, 10) 4 | 5 | fun main() { 6 | var t = readln().toInt() 7 | 8 | val result = buildString { 9 | SECS.forEach { 10 | val count = t / it 11 | t -= it * count 12 | append(count, " ") 13 | } 14 | } 15 | 16 | if (0 < t) return println(-1) 17 | 18 | println(result) 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_2576/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2576 2 | 3 | import kotlin.math.min 4 | 5 | fun main() { 6 | var sum = 0 7 | var minValue = 100 8 | repeat(times = 7) { 9 | val n = readln().toInt() 10 | if (n and 1 == 0) return@repeat 11 | 12 | sum += n 13 | minValue = min(minValue, n) 14 | } 15 | if (sum < 1) return print(-1) 16 | 17 | print("$sum\n$minValue") 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_14425/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14425 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | val set = HashSet() 10 | repeat(n) { set.add(readln()) } 11 | 12 | var count = 0 13 | repeat(m) { if (readln() in set) ++count } 14 | 15 | println(count) 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_20115/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_20115 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val st = StringTokenizer(readln()) 8 | val quantities = DoubleArray(n) { st.nextToken().toDouble() }.apply { sort() } 9 | 10 | var maxQuantity = quantities.last() 11 | for (i in 0..n - 2) maxQuantity += quantities[i] / 2.0 12 | 13 | print(maxQuantity) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_2075/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2075 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val nums = IntArray(size = n * n) 9 | repeat(n) { row -> 10 | val st = StringTokenizer(readln()) 11 | repeat(n) { col -> nums[n * row + col] = st.nextToken().toInt() } 12 | } 13 | nums.sortDescending() 14 | 15 | print(nums[n - 1]) 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_3745/Main.java: -------------------------------------------------------------------------------- 1 | package boj_3745; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 번 () 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/ 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 15 | } 16 | } -------------------------------------------------------------------------------- /src/boj_10804/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10804 2 | 3 | fun main() { 4 | val cards = IntArray(size = 20) { it + 1 } 5 | repeat(times = 10) { 6 | var (i, j) = readln().split(" ").map { it.toInt() - 1 } 7 | while (i < j) { 8 | val tmp = cards[i] 9 | cards[i++] = cards[j] 10 | cards[j--] = tmp 11 | } 12 | } 13 | 14 | print(cards.joinToString(separator = " ")) 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_21312/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_21312 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val nums = IntArray(size = 3) { st.nextToken().toInt() } 8 | 9 | val odds = nums.filter { it and 1 == 1 } 10 | if (odds.isNotEmpty()) return print(odds.fold(initial = 1) { acc, num -> acc * num }) 11 | 12 | print(nums.fold(initial = 1) { acc, num -> acc * num }) 13 | } 14 | -------------------------------------------------------------------------------- /src/boj_17212/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17212 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | val coinUnits = intArrayOf(1, 2, 5, 7) 6 | 7 | val minCoinCounts = IntArray(size = n + 1) 8 | for (i in 1..n) { 9 | minCoinCounts[i] = coinUnits.minOf { coinUnit -> 10 | if (coinUnit <= i) minCoinCounts[i - coinUnit] + 1 else Int.MAX_VALUE 11 | } 12 | } 13 | 14 | print(minCoinCounts[n]) 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_9657/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9657 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val isSkWinnable = BooleanArray(size = 1_001) 7 | isSkWinnable[1] = true 8 | isSkWinnable[3] = true 9 | isSkWinnable[4] = true 10 | for (i in 5..n) { 11 | isSkWinnable[i] = !isSkWinnable[i - 1] || !isSkWinnable[i - 3] || !isSkWinnable[i - 4] 12 | } 13 | 14 | print(if (isSkWinnable[n]) "SK" else "CY") 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_15829/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15829 2 | 3 | fun main() { 4 | val l = readln().toInt() 5 | val input = readln() 6 | 7 | var hash = 0L 8 | for (i in 0 until l) { 9 | val a = input[i] - 'a' + 1 10 | var r = 1L 11 | repeat(i) { 12 | r *= 31L 13 | r %= 1_234_567_891L 14 | } 15 | hash += a * r 16 | hash %= 1_234_567_891L 17 | } 18 | 19 | print(hash) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_2480/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2480 2 | 3 | fun main() { 4 | val values = readln().split(" ").map { it.toInt() }.sorted() 5 | 6 | val result = when { 7 | values[0] == values[1] && values[1] == values[2] -> values[0] * 1_000 + 10_000 8 | values[0] == values[1] -> values[0] * 100 + 1_000 9 | values[1] == values[2] -> values[1] * 100 + 1_000 10 | else -> values[2] * 100 11 | } 12 | print(result) 13 | } 14 | -------------------------------------------------------------------------------- /src/boj_17626/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17626 2 | 3 | import kotlin.math.min 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val memory = IntArray(size = n + 1) 9 | for (i in 1..n) { 10 | memory[i] = memory[i - 1] + 1 11 | var j = 1 12 | while (j * j <= i) { 13 | memory[i] = min(memory[i], b = memory[i - j * j] + 1) 14 | ++j 15 | } 16 | } 17 | 18 | print(memory[n]) 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_20312/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_20312 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val st = StringTokenizer(readln()) 9 | var sum = 0L 10 | var previous = 0L 11 | for (i in 0 until n - 1) { 12 | previous = (previous + 1) * st.nextToken().toLong() % 1_000_000_007L 13 | sum += previous 14 | sum %= 1_000_000_007L 15 | } 16 | 17 | print(sum) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_9658/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9658 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | val isSkWinnable = BooleanArray(size = 1_001) 7 | isSkWinnable[2] = true 8 | isSkWinnable[4] = true 9 | 10 | for (i in 5..n) { 11 | if (!isSkWinnable[i - 1] || !isSkWinnable[i - 3] || !isSkWinnable[i - 4]) { 12 | isSkWinnable[i] = true 13 | } 14 | } 15 | 16 | print(if (isSkWinnable[n]) "SK" else "CY") 17 | } 18 | -------------------------------------------------------------------------------- /src/boj_10101/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10101 2 | 3 | fun main() { 4 | val angles = buildList { repeat(times = 3) { add(readln().toInt()) } } 5 | 6 | val result = when { 7 | angles.sum() != 180 || angles.any { it == 0 } -> "Error" 8 | angles.all { it == 60 } -> "Equilateral" 9 | angles[0] == angles[1] || angles[0] == angles[2] || angles[1] == angles[2] -> "Isosceles" 10 | else -> "Scalene" 11 | } 12 | 13 | println(result) 14 | } 15 | -------------------------------------------------------------------------------- /src/boj_1085/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1085 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val x = st.nextToken().toInt() 8 | val y = st.nextToken().toInt() 9 | val w = st.nextToken().toInt() 10 | val h = st.nextToken().toInt() 11 | 12 | val min = x.coerceAtMost(y) 13 | .coerceAtMost(maximumValue = w - x) 14 | .coerceAtMost(maximumValue = h - y) 15 | 16 | println(min) 17 | } 18 | -------------------------------------------------------------------------------- /src/boj_10799/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10799 2 | 3 | import java.util.Stack 4 | 5 | fun main() { 6 | val brackets = readln() 7 | val stack = Stack() 8 | var size = 0 9 | for (i in brackets.indices) { 10 | if (brackets[i] == '(') { 11 | stack.push(brackets[i]) 12 | continue 13 | } 14 | 15 | stack.pop() 16 | size += if (brackets[i - 1] == '(') stack.size else 1 17 | } 18 | 19 | print(size) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_17608/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17608 2 | 3 | import java.util.Stack 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val heights = IntArray(n) 9 | repeat(n) { heights[it] = readln().toInt() } 10 | 11 | val stack = Stack() 12 | stack.push(heights.last()) 13 | for (i in heights.lastIndex - 1 downTo 0) { 14 | if (stack.isNotEmpty() && stack.peek() < heights[i]) stack.push(heights[i]) 15 | } 16 | 17 | print(stack.size) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_2437/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2437 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val st = StringTokenizer(readln()) 8 | 9 | val weights = IntArray(n) 10 | repeat(n) { weights[it] = st.nextToken().toInt() } 11 | 12 | weights.sort() 13 | var sum = 0 14 | for (weight in weights) { 15 | if (sum + 1 < weight) break 16 | 17 | sum += weight 18 | } 19 | 20 | println(sum + 1) 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_25305/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25305 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val k = st.nextToken().toInt() 9 | 10 | val scores = IntArray(n) 11 | st = StringTokenizer(readln()) 12 | repeat(n) { scores[it] = st.nextToken().toInt() } 13 | 14 | scores.sortDescending() 15 | val cutLineScore = scores[k - 1] 16 | 17 | println(cutLineScore) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_2670/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2670 2 | 3 | import kotlin.math.max 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val memory = DoubleArray(n) 9 | memory[0] = readln().toDouble() 10 | var maxValue = 0.0 11 | for (i in 1 until n) { 12 | val float = readln().toDouble() 13 | memory[i] = max(float, b = memory[i - 1] * float) 14 | maxValue = max(maxValue, memory[i]) 15 | } 16 | 17 | print(String.format("%.3f", maxValue)) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_10093/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10093 2 | 3 | fun main() { 4 | val nums = readln().split(" ").map { it.toLong() }.sorted() 5 | 6 | System.out.bufferedWriter().use { 7 | val count = (nums[1] - nums[0] - 1L).coerceAtLeast(minimumValue = 0L) 8 | it.write(count.toString()) 9 | if (count < 1L) return it.flush() 10 | 11 | it.write("\n") 12 | it.write((nums[0] + 1L until nums[1]).joinToString(separator = " ")) 13 | it.flush() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/boj_20300/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_20300 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val st = StringTokenizer(readln()) 8 | val loss = LongArray(n) { st.nextToken().toLong() }.apply { sort() } 9 | 10 | var m = if (n and 1 == 0) 0L else loss.last() 11 | var left = 0 12 | var right = n - if (n and 1 == 0) 1 else 2 13 | while (left < right) m = maxOf(m, b = loss[left++] + loss[right--]) 14 | 15 | print(m) 16 | } 17 | -------------------------------------------------------------------------------- /src/boj_3986/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_3986 2 | 3 | import java.util.Stack 4 | 5 | fun main() { 6 | var count = 0 7 | repeat(readln().toInt()) { 8 | val stack = Stack() 9 | readln().forEach { 10 | if (stack.isNotEmpty() && stack.peek() == it) { 11 | stack.pop() 12 | } else { 13 | stack.push(it) 14 | } 15 | } 16 | if (stack.isEmpty()) ++count 17 | } 18 | 19 | print(count) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_11478/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11478 2 | 3 | fun main() { 4 | val s = readln() 5 | 6 | val length = s.length 7 | val set = HashSet() 8 | var window = 1 9 | while (window <= length) { 10 | for (startIdx in s.indices) { 11 | val endIdx = startIdx + window 12 | if (length < endIdx) continue 13 | 14 | set.add(s.substring(startIdx, endIdx)) 15 | } 16 | ++window 17 | } 18 | 19 | println(set.size) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_2558/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2558; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * 백준 온라인 저지 2558번 (A + B - 2) 문제풀이 7 | * 8 | * @see https://www.acmicpc.net/problem/2558 9 | * @author devetude 10 | */ 11 | public class Main { 12 | public static void main(String[] args) throws Exception { 13 | // 입력을 받음 14 | Scanner sc = new Scanner(System.in); 15 | int A = sc.nextInt(); 16 | int B = sc.nextInt(); 17 | sc.close(); 18 | 19 | // 결과 값 출력 20 | System.out.println(A + B); 21 | } 22 | } -------------------------------------------------------------------------------- /src/boj_1351/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1351 2 | 3 | import java.util.StringTokenizer 4 | 5 | var p: Int = 0 6 | var q: Int = 0 7 | 8 | val a: HashMap = HashMap().apply { this[0L] = 1L } 9 | 10 | fun main() { 11 | val st = StringTokenizer(readln()) 12 | val n = st.nextToken().toLong() 13 | p = st.nextToken().toInt() 14 | q = st.nextToken().toInt() 15 | 16 | print(dp(n)) 17 | } 18 | 19 | fun dp(i: Long): Long = a[i] ?: (dp(i = i / p) + dp(i = i / q)).also { a[i] = it } 20 | -------------------------------------------------------------------------------- /src/boj_17271/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17271 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | val counts = IntArray(size = 10_001) 11 | counts[0] = 1 12 | for (i in 1..n) { 13 | counts[i] = counts[i - 1] % 1_000_000_007 14 | if (m <= i) counts[i] += counts[i - m] % 1_000_000_007 15 | } 16 | 17 | print(counts[n] % 1_000_000_007) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_5585/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_5585 2 | 3 | val COINS = arrayOf(500, 100, 50, 10, 5, 1) 4 | 5 | fun main() { 6 | val cost = readln().toInt() 7 | 8 | var change = 1_000 - cost 9 | var totalCoinCount = 0 10 | for (coin in COINS) { 11 | if (change == 0) break 12 | if (change < coin) continue 13 | 14 | val coinCount = change / coin 15 | change -= coin * coinCount 16 | totalCoinCount += coinCount 17 | } 18 | 19 | println(totalCoinCount) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_7785/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_7785 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val set = HashSet() 7 | repeat(readln().toInt()) { 8 | val st = StringTokenizer(readln()) 9 | val name = st.nextToken() 10 | if (st.nextToken()[0] == 'e') set.add(name) else set.remove(name) 11 | } 12 | 13 | System.out.bufferedWriter().use { 14 | it.write(set.sortedDescending().joinToString(separator = "\n")) 15 | it.flush() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/boj_10171/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10171; 2 | 3 | /** 4 | * 백준 온라인 저지 10171 (고양이) 문제풀이 5 | * 6 | * @author devetude 7 | * @see https://www.acmicpc.net/problem/10171 8 | */ 9 | public class Main { 10 | public static void main(String args[]) { 11 | StringBuilder sb = new StringBuilder(); 12 | sb.append("\\ /\\\n"); 13 | sb.append(" ) ( ')\n"); 14 | sb.append("( / )\n"); 15 | sb.append(" \\(__)|"); 16 | 17 | System.out.print(sb.toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_1373/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1373 2 | 3 | fun main() { 4 | val binaryStr = readln() 5 | 6 | val result = buildString { 7 | for (i in binaryStr.lastIndex downTo 0 step 3) { 8 | var sum = 0 9 | for (j in i downTo i - 2) { 10 | if (j < 0) break 11 | if (binaryStr[j] == '0') continue 12 | sum += (1 shl (i - j)) 13 | } 14 | append(sum) 15 | } 16 | }.reversed() 17 | 18 | print(result) 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_13164/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13164 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val k = st.nextToken().toInt() 9 | 10 | st = StringTokenizer(readln()) 11 | val heightOf = IntArray(n) { st.nextToken().toInt() } 12 | 13 | val diffs = IntArray(size = n - 1) { heightOf[it + 1] - heightOf[it] }.apply { sort() } 14 | var cost = 0 15 | for (i in 0 until n - k) cost += diffs[i] 16 | 17 | print(cost) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_13414/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13414 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val k = st.nextToken().toInt() 8 | val l = st.nextToken().toInt() 9 | 10 | val set = LinkedHashSet() 11 | repeat(l) { readln().also(set::remove).also(set::add) } 12 | val result = set.joinToString(separator = "\n", limit = k, truncated = "") 13 | 14 | System.out.bufferedWriter().use { 15 | it.write(result) 16 | it.flush() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_1793/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1793 2 | 3 | import java.math.BigInteger 4 | 5 | fun main() { 6 | val counts = Array(size = 251) { BigInteger.ONE } 7 | for (i in 2..250) { 8 | counts[i] = counts[i - 1] + (counts[i - 2] shl 1) 9 | } 10 | 11 | System.out.bufferedWriter().use { 12 | while (true) { 13 | val n = readlnOrNull()?.toInt() ?: break 14 | 15 | it.write(counts[n].toString()) 16 | it.write("\n") 17 | } 18 | 19 | it.flush() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_18110/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_18110 2 | 3 | import kotlin.math.roundToInt 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | if (n == 0) return print(0) 8 | 9 | val ranks = IntArray(n) { readln().toInt() }.apply { sort() } 10 | val except = (n * 0.15).roundToInt() 11 | val sum = ranks.foldIndexed(initial = 0) { i, acc, rank -> 12 | acc + if (i in except until n - except) rank else 0 13 | } 14 | val avg = (sum.toDouble() / (n - (except shl 1))).roundToInt() 15 | 16 | print(avg) 17 | } 18 | -------------------------------------------------------------------------------- /src/boj_25099/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25099 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | val set = HashSet() 8 | repeat(n) { 9 | val word = readln() 10 | val key = String(word.toCharArray().apply { sort() }) 11 | if (key !in set) { 12 | bw.write(word) 13 | bw.write("\n") 14 | } 15 | set.add(key) 16 | } 17 | 18 | bw.flush() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_2847/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2847 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | val scores = IntArray(n) 6 | repeat(n) { scores[it] = readln().toInt() } 7 | 8 | var maxScore = scores.last() 9 | var downCount = 0 10 | for (i in scores.lastIndex - 1 downTo 0) { 11 | val score = scores[i] 12 | if (maxScore <= score) { 13 | downCount += score - --maxScore 14 | } else { 15 | maxScore = score 16 | } 17 | } 18 | 19 | println(downCount) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_1259/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1259 2 | 3 | fun main() { 4 | System.out.bufferedWriter().use { 5 | while (true) { 6 | val input = readln() 7 | if (input == "0") return it.flush() 8 | 9 | var i = 0 10 | var j = input.lastIndex 11 | var result = "yes" 12 | while (i < j) { 13 | if (input[i++] != input[j--]) result = "no" 14 | } 15 | 16 | it.write(result) 17 | it.write("\n") 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_3273/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_3273 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val st = StringTokenizer(readln()) 9 | val a = IntArray(n) { st.nextToken().toInt() } 10 | 11 | val x = readln().toInt() 12 | 13 | val checks = BooleanArray(size = 1_000_001) 14 | var count = 0 15 | a.forEach { 16 | val diff = x - it 17 | if (diff in 1..1_000_000 && checks[diff]) ++count else checks[it] = true 18 | } 19 | 20 | print(count) 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_6198/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_6198 2 | 3 | import java.util.Stack 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val heights = IntArray(n) { readln().toInt() } 8 | 9 | val stack = Stack>() 10 | var count = 0L 11 | for (i in n - 1 downTo 0) { 12 | while (stack.isNotEmpty() && stack.peek().second < heights[i]) stack.pop() 13 | count += (if (stack.isNotEmpty()) stack.peek().first else n) - i - 1 14 | stack.push(i to heights[i]) 15 | } 16 | 17 | print(count) 18 | } 19 | -------------------------------------------------------------------------------- /src/boj_1715/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1715 2 | 3 | import java.util.PriorityQueue 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val pq = PriorityQueue() 8 | repeat(n) { pq.offer(readln().toInt()) } 9 | 10 | var totalCompareTimes = 0 11 | while (1 < pq.size) { 12 | val first = pq.poll() 13 | val second = pq.poll() 14 | val compareTimes = first + second 15 | totalCompareTimes += compareTimes 16 | pq.offer(compareTimes) 17 | } 18 | 19 | println(totalCompareTimes) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_2295/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2295 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | val u = IntArray(n) { readln().toInt() }.apply { sort() } 6 | 7 | val twoSums = mutableListOf() 8 | for (i in u.indices) { 9 | for (j in i until n) twoSums.add(u[i] + u[j]) 10 | } 11 | twoSums.sort() 12 | 13 | for (i in n - 1 downTo 0) { 14 | for (j in 0 until i) { 15 | val diff = u[i] - u[j] 16 | if (-1 < twoSums.binarySearch(diff)) return print(u[i]) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_2631/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2631 2 | 3 | import kotlin.math.max 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val nums = IntArray(n) 9 | val maxSizes = IntArray(n) 10 | var maxSize = 0 11 | repeat(n) { 12 | nums[it] = readln().toInt() 13 | maxSizes[it] = 1 14 | for (i in 0.. min += sign * sb.toIntAndClear() 12 | else -> sb.append(it) 13 | } 14 | 15 | if (it == '-') sign = -1 16 | } 17 | min += sign * sb.toIntAndClear() 18 | 19 | println(min) 20 | } 21 | 22 | private fun StringBuilder.toIntAndClear(): Int = toString().toInt().also { clear() } 23 | -------------------------------------------------------------------------------- /src/boj_2417/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2417 2 | 3 | fun main() = print(approximateSqrtOf(readln().toLong())) 4 | 5 | fun approximateSqrtOf(n: Long): Long { 6 | if (n < 1) return 0L 7 | 8 | var start = 1L 9 | var end = n 10 | var mid = start + end shr 1 11 | 12 | while (start <= end) { 13 | when { 14 | n / mid < mid -> end = mid - 1L 15 | mid * mid == n -> return mid 16 | else -> start = mid + 1L 17 | } 18 | mid = start + end shr 1 19 | } 20 | 21 | return end + 1L 22 | } 23 | -------------------------------------------------------------------------------- /src/boj_2743/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2743; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 2743번 (단어 길이 재기) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/2743 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | 17 | // 결과 값 출력 18 | System.out.println(br.readLine().length()); 19 | 20 | br.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/boj_15903/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15903 2 | 3 | import java.util.PriorityQueue 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | var st = StringTokenizer(readln()) 8 | val n = st.nextToken().toInt() 9 | val m = st.nextToken().toInt() 10 | st = StringTokenizer(readln()) 11 | val pq = PriorityQueue() 12 | repeat(n) { pq.add(st.nextToken().toLong()) } 13 | 14 | repeat(m) { 15 | val minSum = pq.poll() + pq.poll() 16 | repeat(times = 2) { pq.offer(minSum) } 17 | } 18 | 19 | println(pq.sum()) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_2293/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2293 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val k = st.nextToken().toInt() 9 | 10 | val coins = IntArray(n) 11 | repeat(n) { coins[it] = readln().toInt() } 12 | 13 | val memory = IntArray(size = k + 1) 14 | memory[0] = 1 15 | for (i in 0 until n) { 16 | for (j in coins[i]..k) { 17 | memory[j] += memory[j - coins[i]] 18 | } 19 | } 20 | 21 | print(memory[k]) 22 | } 23 | -------------------------------------------------------------------------------- /src/boj_10871/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10871 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val x = st.nextToken().toShort() 9 | 10 | System.out.bufferedWriter().use { bw -> 11 | st = StringTokenizer(readln()) 12 | repeat(n) { 13 | val a = st.nextToken() 14 | if (a.toShort() < x) { 15 | bw.write(a) 16 | bw.write(" ") 17 | } 18 | } 19 | bw.flush() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_26069/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_26069 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val dancerNames = HashSet() 9 | dancerNames.add("ChongChong") 10 | repeat(n) { 11 | val st = StringTokenizer(readln()) 12 | val a = st.nextToken() 13 | val b = st.nextToken() 14 | 15 | if (a in dancerNames || b in dancerNames) { 16 | dancerNames.add(a) 17 | dancerNames.add(b) 18 | } 19 | } 20 | 21 | println(dancerNames.size) 22 | } 23 | -------------------------------------------------------------------------------- /src/boj_9251/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9251 2 | 3 | import kotlin.math.max 4 | 5 | fun main() { 6 | val a = readln() 7 | val b = readln() 8 | 9 | val lcs = Array(size = a.length + 1) { IntArray(size = b.length + 1) } 10 | for (i in 1..a.length) { 11 | for (j in 1..b.length) { 12 | lcs[i][j] = if (a[i - 1] == b[j - 1]) { 13 | lcs[i - 1][j - 1] + 1 14 | } else { 15 | max(lcs[i - 1][j], lcs[i][j - 1]) 16 | } 17 | } 18 | } 19 | 20 | print(lcs[a.length][b.length]) 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_1267/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1267 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val st = StringTokenizer(readln()) 9 | var yCost = 0 10 | var mCost = 0 11 | repeat(n) { 12 | val sec = st.nextToken().toInt() 13 | yCost += sec / 30 * 10 + 10 14 | mCost += sec / 60 * 15 + 15 15 | } 16 | val result = when { 17 | yCost < mCost -> "Y $yCost" 18 | mCost < yCost -> "M $mCost" 19 | else -> "Y M $yCost" 20 | } 21 | 22 | print(result) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_1629/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1629 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val a = st.nextToken().toLong() 8 | val b = st.nextToken().toInt() 9 | val c = st.nextToken().toInt() 10 | 11 | print(a.pow(b, c)) 12 | } 13 | 14 | fun Long.pow(e: Int, mod: Int): Long { 15 | if (e == 1) return this % mod 16 | 17 | val tmp = pow(e = e shr 1, mod) 18 | val squareModOfTmp = tmp * tmp % mod 19 | 20 | return if (e and 1 == 1) squareModOfTmp * this % mod else squareModOfTmp 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_25418/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25418 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.min 5 | 6 | fun main() { 7 | val st = StringTokenizer(readln()) 8 | val a = st.nextToken().toInt() 9 | val k = st.nextToken().toInt() 10 | 11 | val minOpTimes = IntArray(size = k + 1) 12 | for (i in a + 1..k) { 13 | minOpTimes[i] = minOpTimes[i - 1] + 1 14 | if (i and 1 == 0 && a shl 1 <= i) { 15 | minOpTimes[i] = min(minOpTimes[i], b = minOpTimes[i shr 1] + 1) 16 | } 17 | } 18 | 19 | print(minOpTimes[k]) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_10172/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10172; 2 | 3 | /** 4 | * 백준 온라인 저지 10172번 (개) 문제풀이 5 | * 6 | * @see https://www.acmicpc.net/problem/10172 7 | * @author devetude 8 | */ 9 | public class Main { 10 | public static void main(String args[]) throws Exception { 11 | // 개 모양 문자열을 버퍼를 이용하여 만듬 12 | StringBuilder sb = new StringBuilder(); 13 | sb.append("|\\_/|\n"); 14 | sb.append("|q p| /}\n"); 15 | sb.append("( 0 )\"\"\"\\\n"); 16 | sb.append("|\"^\"` |\n"); 17 | sb.append("||_/=\\\\__|"); 18 | 19 | // 결과 값 출력 20 | System.out.println(sb.toString()); 21 | } 22 | } -------------------------------------------------------------------------------- /src/boj_14916/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14916 2 | 3 | fun main() { 4 | var n = readln().toInt() 5 | 6 | var fiveCoinCount = n / 5 7 | n -= 5 * fiveCoinCount 8 | var twoCoinCount = n / 2 9 | n -= 2 * twoCoinCount 10 | 11 | val totalCoinCount = fiveCoinCount + twoCoinCount 12 | if (totalCoinCount == 0) return println(-1) 13 | 14 | if (0 < n) { 15 | if (fiveCoinCount == 0) return println(-1) 16 | 17 | --fiveCoinCount 18 | n += 5 19 | twoCoinCount += n / 2 20 | } 21 | 22 | println(fiveCoinCount + twoCoinCount) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_23971/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_23971 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val h = st.nextToken().toInt() 8 | val w = st.nextToken().toInt() 9 | val n = st.nextToken().toInt() 10 | val m = st.nextToken().toInt() 11 | 12 | print(availableSize(h, n) * availableSize(w, m)) 13 | } 14 | 15 | fun availableSize(length: Int, space: Int): Int { 16 | val unit = space + 1 17 | val quotient = length / unit 18 | 19 | return if (unit * quotient == length) quotient else quotient + 1 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_2446/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2446 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | repeat(n) { row -> 8 | repeat(row) { bw.write(" ") } 9 | repeat(times = (n - row shl 1) - 1) { bw.write("*") } 10 | bw.write("\n") 11 | } 12 | for (i in 1 until n) { 13 | repeat(times = n - i - 1) { bw.write(" ") } 14 | repeat(times = (i shl 1) + 1) { bw.write("*") } 15 | bw.write("\n") 16 | } 17 | bw.flush() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_2588/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2588 2 | 3 | fun main() { 4 | val a = readln().toInt() 5 | val bStr = readln() 6 | 7 | val result = buildString { 8 | var sum = 0 9 | var pow = 1 10 | repeat(times = 3) { 11 | val element = a * Character.getNumericValue(bStr[2 - it]) 12 | appendLine(element) 13 | sum += element * pow 14 | pow *= 10 15 | } 16 | appendLine(sum) 17 | } 18 | 19 | System.out.bufferedWriter().use { 20 | it.write(result) 21 | it.flush() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_17219/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17219 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | val map = HashMap() 11 | repeat(n) { 12 | st = StringTokenizer(readln()) 13 | map[st.nextToken()] = st.nextToken() 14 | } 15 | val result = buildString { repeat(m) { appendLine(map[readln()]) } } 16 | 17 | System.out.bufferedWriter().use { 18 | it.write(result) 19 | it.flush() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_2444/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2444 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | repeat(n) { row -> 8 | repeat(times = n - row - 1) { bw.write(" ") } 9 | repeat(times = (row shl 1) + 1) { bw.write("*") } 10 | bw.write("\n") 11 | } 12 | for (i in n - 1 downTo 1) { 13 | repeat(times = n - i) { bw.write(" ") } 14 | repeat(times = (i shl 1) - 1) { bw.write("*") } 15 | bw.write("\n") 16 | } 17 | bw.flush() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_1026/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1026 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val stA = StringTokenizer(readln()) 9 | val stB = StringTokenizer(readln()) 10 | val aArr = IntArray(n) 11 | val bArr = IntArray(n) 12 | repeat(n) { 13 | aArr[it] = stA.nextToken().toInt() 14 | bArr[it] = stB.nextToken().toInt() 15 | } 16 | 17 | aArr.apply { sort() } 18 | .also { bArr.sortDescending() } 19 | .foldIndexed(initial = 0) { i, acc, a -> acc + a * bArr[i] } 20 | .run(::print) 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_5648/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_5648 2 | 3 | import java.util.LinkedList 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | val list = LinkedList() 8 | var line = readlnOrNull() 9 | while (line != null) { 10 | val st = StringTokenizer(line) 11 | while (st.hasMoreTokens()) list.add(st.nextToken().reversed().toLong()) 12 | line = readlnOrNull() 13 | } 14 | list.removeFirst() 15 | list.sort() 16 | 17 | System.out.bufferedWriter().use { 18 | it.write(list.joinToString(separator = "\n")) 19 | it.flush() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_1417/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1417 2 | 3 | import java.util.PriorityQueue 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val myPoint = readln().toInt() 8 | val otherPoints = PriorityQueue(compareByDescending { it }) 9 | repeat(times = n - 1) { otherPoints.offer(readln().toInt()) } 10 | 11 | var buyCount = 0 12 | while (otherPoints.isNotEmpty() && myPoint + buyCount <= otherPoints.peek()) { 13 | val firstOtherPoint = otherPoints.poll() 14 | otherPoints.offer(firstOtherPoint - 1) 15 | ++buyCount 16 | } 17 | 18 | println(buyCount) 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_16435/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_16435 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | st = StringTokenizer(readln()) 10 | val treeHeights = IntArray(n) 11 | repeat(n) { treeHeights[it] = st.nextToken().toInt() } 12 | 13 | treeHeights.sort() 14 | var currentHeight = m 15 | for (treeHeight in treeHeights) { 16 | if (currentHeight < treeHeight) break 17 | 18 | ++currentHeight 19 | } 20 | 21 | println(currentHeight) 22 | } 23 | -------------------------------------------------------------------------------- /src/boj_10610/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10610 2 | 3 | import java.util.PriorityQueue 4 | 5 | fun main() { 6 | val n = readln() 7 | 8 | val pq = PriorityQueue(compareByDescending { it }) 9 | n.forEach(pq::offer) 10 | 11 | var placeValueSum = 0 12 | val result = buildString { 13 | while (pq.isNotEmpty()) { 14 | val num = Character.getNumericValue(pq.poll()) 15 | placeValueSum += num 16 | append(num) 17 | } 18 | } 19 | 20 | if (placeValueSum % 3 != 0 || result.last() != '0') return println(-1) 21 | 22 | println(result) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_1931/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1931 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val schedules = Array(n) { 8 | val st = StringTokenizer(readln()) 9 | st.nextToken().toInt() to st.nextToken().toInt() 10 | }.apply { sortWith(compareBy> { it.second }.thenBy { it.first }) } 11 | 12 | var current = 0 13 | var size = 0 14 | schedules.forEach { (start, end) -> 15 | if (current <= start) { 16 | ++size 17 | current = end 18 | } 19 | } 20 | 21 | print(size) 22 | } 23 | -------------------------------------------------------------------------------- /src/boj_19532/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_19532 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val a = st.nextToken().toInt() 8 | val b = st.nextToken().toInt() 9 | val c = st.nextToken().toInt() 10 | val d = st.nextToken().toInt() 11 | val e = st.nextToken().toInt() 12 | val f = st.nextToken().toInt() 13 | 14 | val denominator = b * d - a * e 15 | val x = (b * f - c * e) / denominator 16 | val y = (c * d - a * f) / denominator 17 | val result = buildString { append(x, " ", y) } 18 | 19 | println(result) 20 | } 21 | -------------------------------------------------------------------------------- /src/boj_14494/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14494 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | val map = Array(size = n + 1) { row -> 11 | LongArray(size = m + 1) { col -> 12 | if (row == 1 || col == 1) 1 else 0 13 | } 14 | } 15 | 16 | for (i in 2..n) { 17 | for (j in 2..m) { 18 | map[i][j] = (map[i - 1][j - 1] + map[i - 1][j] + map[i][j - 1]) % 1_000_000_007 19 | } 20 | } 21 | 22 | print(map[n][m]) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_1439/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1439 2 | 3 | import kotlin.math.min 4 | 5 | fun main() { 6 | val s = readln() 7 | if (s.isEmpty()) return println(0) 8 | 9 | var previousChar = s[0] 10 | var zeroGroupCount = if (previousChar == '0') 1 else 0 11 | var oneGroupCount = if (previousChar == '1') 1 else 0 12 | for (i in 1..s.lastIndex) { 13 | val char = s[i] 14 | if (char == previousChar) continue 15 | 16 | if (previousChar == '0') ++oneGroupCount else ++zeroGroupCount 17 | previousChar = char 18 | } 19 | 20 | println(min(zeroGroupCount, oneGroupCount)) 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_17073/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17073 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val w = st.nextToken().toDouble() 9 | 10 | val degree = IntArray(size = n + 1) 11 | repeat(times = n - 1) { 12 | st = StringTokenizer(readln()) 13 | val u = st.nextToken().toInt() 14 | ++degree[u] 15 | val v = st.nextToken().toInt() 16 | ++degree[v] 17 | } 18 | 19 | var leafSize = 0 20 | for (i in 2..n) if (degree[i] == 1) ++leafSize 21 | 22 | print(w / leafSize) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_2475/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2475; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * 백준 온라인 저지 2475번 (검증수) 문제풀이 7 | * 8 | * @see https://www.acmicpc.net/problem/2475 9 | * @author devetude 10 | */ 11 | public class Main { 12 | public static void main(String args[]) throws Exception { 13 | // 입력 값을 받음 14 | Scanner sc = new Scanner(System.in); 15 | int powerSum = 0; 16 | 17 | for (int i = 0; i < 5; i++) { 18 | // 입력 값의 제곱의 합을 구함 19 | powerSum += Math.pow(sc.nextInt(), 2); 20 | } 21 | 22 | sc.close(); 23 | 24 | // 제곱들의 합에서 10을 나눈 나머지를 결과 값으로 출력 25 | System.out.println(powerSum % 10); 26 | } 27 | } -------------------------------------------------------------------------------- /src/boj_10810/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10810 2 | 3 | fun main() { 4 | val (n, m) = readln().split(" ").map { it.toInt() } 5 | 6 | val buckets = MutableList(size = n + 1) { 0 } 7 | repeat(m) { 8 | val (i, j, k) = readln().split(" ").map { it.toInt() } 9 | for (idx in i..j) { 10 | if (buckets[idx] != k) buckets[idx] = k 11 | } 12 | } 13 | val result = buildString { 14 | for (idx in 1 until buckets.size - 1) { 15 | append(buckets[idx]) 16 | append(" ") 17 | } 18 | append(buckets.last()) 19 | } 20 | 21 | println(result) 22 | } 23 | -------------------------------------------------------------------------------- /src/boj_10813/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10813 2 | 3 | fun main() { 4 | val (n, m) = readln().split(" ").map { it.toInt() } 5 | 6 | val buckets = MutableList(size = n + 1) { it } 7 | repeat(m) { 8 | val (i, j) = readln().split(" ").map { it.toInt() } 9 | val temp = buckets[i] 10 | buckets[i] = buckets[j] 11 | buckets[j] = temp 12 | } 13 | 14 | val result = buildString { 15 | for (idx in 1 until buckets.size - 1) { 16 | append(buckets[idx]) 17 | append(" ") 18 | } 19 | append(buckets.last()) 20 | } 21 | 22 | println(result) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_2745/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2745 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.pow 5 | 6 | fun main() { 7 | val st = StringTokenizer(readln()) 8 | val n = st.nextToken() 9 | val b = st.nextToken().toInt() 10 | 11 | // val result = n.toInt(b) 12 | var result = 0 13 | n.forEachIndexed { i, c -> result += b.pow(n = n.length - i - 1) * c.toBase10() } 14 | 15 | println(result) 16 | } 17 | 18 | private fun Char.toBase10(): Int = 19 | if ('A'.code <= code) code - 'A'.code + 10 else code - '0'.code 20 | 21 | private fun Int.pow(n: Int): Int = toDouble().pow(n.toDouble()).toInt() 22 | -------------------------------------------------------------------------------- /src/boj_1269/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1269 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val aSize = st.nextToken().toInt() 8 | val bSize = st.nextToken().toInt() 9 | 10 | st = StringTokenizer(readln()) 11 | val aSet = HashSet() 12 | repeat(aSize) { aSet.add(st.nextToken().toInt()) } 13 | 14 | st = StringTokenizer(readln()) 15 | val bSet = HashSet() 16 | repeat(bSize) { bSet.add(st.nextToken().toInt()) } 17 | 18 | val intersectSize = aSet.intersect(bSet).size 19 | 20 | println(aSet.size + bSet.size - 2 * intersectSize) 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_16395/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_16395 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val k = st.nextToken().toInt() 9 | 10 | val nums = Array(size = n + 1) { IntArray(size = n + 1) } 11 | nums[1][1] = 1 12 | for (row in 1..n) { 13 | for (col in 1..row) { 14 | nums[row][col] = if (col == 1 || col == row) { 15 | 1 16 | } else { 17 | nums[row - 1][col - 1] + nums[row - 1][col] 18 | } 19 | } 20 | } 21 | 22 | print(nums[n][k]) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_1543/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1543 2 | 3 | fun main() { 4 | val doc = readln() 5 | val word = readln() 6 | 7 | var s = 0 8 | var count = 0 9 | while (s < doc.length) { 10 | var isMatched = true 11 | for (i in word.indices) { 12 | val j = s + i 13 | if (doc.lastIndex < j || doc[j] != word[i]) { 14 | isMatched = false 15 | break 16 | } 17 | } 18 | s += if (isMatched) { 19 | ++count 20 | word.length 21 | } else { 22 | 1 23 | } 24 | } 25 | 26 | print(count) 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_4358/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_4358 2 | 3 | import java.util.TreeMap 4 | 5 | fun main() { 6 | val map = TreeMap() 7 | var size = 0 8 | while (true) { 9 | val type = readlnOrNull() ?: break 10 | map[type] = map.getOrDefault(type, defaultValue = 0) + 1 11 | ++size 12 | } 13 | 14 | val sb = StringBuilder() 15 | map.forEach { (type, count) -> 16 | sb.append(type, ' ') 17 | sb.appendLine(String.format("%.4f", count * 100.0 / size)) 18 | } 19 | 20 | System.out.bufferedWriter().use { 21 | it.write(sb.toString()) 22 | it.flush() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/boj_9093/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9093 2 | 3 | fun main() { 4 | System.out.bufferedWriter().use { bw -> 5 | repeat(readln().toInt()) { 6 | val sb = StringBuilder() 7 | readln().forEach { c -> 8 | if (c == ' ') { 9 | bw.write(sb.reverse().toString()) 10 | bw.write(" ") 11 | sb.clear() 12 | } else { 13 | sb.append(c) 14 | } 15 | } 16 | bw.write(sb.reverse().toString()) 17 | bw.write("\n") 18 | } 19 | 20 | bw.flush() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/boj_2776/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2776 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val sb = StringBuilder() 7 | repeat(readln().toInt()) { 8 | val n = readln().toInt() 9 | var st = StringTokenizer(readln()) 10 | val set = HashSet(n).apply { repeat(n) { add(st.nextToken().toInt()) } } 11 | 12 | val m = readln().toInt() 13 | st = StringTokenizer(readln()) 14 | repeat(m) { sb.appendLine(if (st.nextToken().toInt() in set) 1 else 0) } 15 | } 16 | 17 | System.out.bufferedWriter().use { 18 | it.write(sb.toString()) 19 | it.flush() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/boj_10869/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10869 2 | 3 | import java.io.BufferedWriter 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | val st = StringTokenizer(readln()) 8 | val a = st.nextToken().toInt() 9 | val b = st.nextToken().toInt() 10 | 11 | System.out.bufferedWriter().use { 12 | with(it) { 13 | writeLine(n = a + b) 14 | writeLine(n = a - b) 15 | writeLine(n = a * b) 16 | writeLine(n = a / b) 17 | writeLine(n = a % b) 18 | } 19 | } 20 | } 21 | 22 | fun BufferedWriter.writeLine(n: Int) { 23 | write(n.toString()) 24 | write("\n") 25 | } 26 | -------------------------------------------------------------------------------- /src/boj_14921/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14921 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.abs 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | 9 | val st = StringTokenizer(readln()) 10 | val a = IntArray(n) { st.nextToken().toInt() } 11 | 12 | var left = 0 13 | var right = a.lastIndex 14 | var b = Int.MAX_VALUE 15 | while (left < right) { 16 | val sum = a[left] + a[right] 17 | if (abs(sum) < abs(b)) b = sum 18 | 19 | when { 20 | sum < 0 -> ++left 21 | 0 < sum -> --right 22 | else -> break 23 | } 24 | } 25 | 26 | print(b) 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_1927/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1927 2 | 3 | import java.util.PriorityQueue 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val pq = PriorityQueue(n) 9 | val result = buildString { 10 | repeat(n) { 11 | when (val x = readln().toInt()) { 12 | 0 -> { 13 | val min = if (pq.isEmpty()) 0 else pq.poll() 14 | appendLine(min) 15 | } 16 | 17 | else -> pq.offer(x) 18 | } 19 | } 20 | } 21 | 22 | System.out.bufferedWriter().use { 23 | it.write(result) 24 | it.flush() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_11286/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11286 2 | 3 | import java.util.PriorityQueue 4 | import kotlin.math.abs 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | 9 | val pq = PriorityQueue(n, compareBy(::abs).thenBy { it }) 10 | val sb = StringBuilder() 11 | repeat(n) { 12 | val x = readln().toInt() 13 | if (x != 0) { 14 | pq.offer(x) 15 | return@repeat 16 | } 17 | 18 | val min = if (pq.isEmpty()) 0 else pq.poll() 19 | sb.appendLine(min) 20 | } 21 | 22 | System.out.bufferedWriter().use { 23 | it.write(sb.toString()) 24 | it.flush() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_13144/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13144 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val st = StringTokenizer(readln()) 9 | val a = IntArray(n) { st.nextToken().toInt() } 10 | 11 | var left = 0 12 | var right = 0 13 | val isVisited = BooleanArray(size = 100_001) 14 | var count = 0L 15 | while (left < n && right < n) { 16 | if (isVisited[a[right]]) { 17 | isVisited[a[left++]] = false 18 | } else { 19 | isVisited[a[right++]] = true 20 | count += right - left 21 | } 22 | } 23 | 24 | print(count) 25 | } 26 | -------------------------------------------------------------------------------- /src/boj_20162/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_20162 2 | 3 | import kotlin.math.max 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val values = IntArray(n) 9 | val maxValueSums = IntArray(n) 10 | var maxValueSum = 0 11 | repeat(n) { 12 | values[it] = readln().toInt() 13 | maxValueSums[it] = values[it] 14 | for (i in 0.. values[c - 'A'] += 10.pow(n = word.lastIndex - i) } 12 | } 13 | 14 | values.sortDescending() 15 | var multiplier = 9 16 | var maxSum = 0 17 | for (value in values) { 18 | if (value == 0) break 19 | 20 | maxSum += value * multiplier-- 21 | } 22 | 23 | println(maxSum) 24 | } 25 | 26 | private fun Int.pow(n: Int): Int = toDouble().pow(n.toDouble()).toInt() 27 | -------------------------------------------------------------------------------- /src/boj_11279/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11279 2 | 3 | import java.util.PriorityQueue 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val pq = PriorityQueue(n, reverseOrder()) 9 | val result = buildString { 10 | repeat(n) { 11 | when (val x = readln().toInt()) { 12 | 0 -> { 13 | val max = if (pq.isEmpty()) 0 else pq.poll() 14 | appendLine(max) 15 | } 16 | 17 | else -> pq.offer(x) 18 | } 19 | } 20 | } 21 | 22 | System.out.bufferedWriter().use { 23 | it.write(result) 24 | it.flush() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_15688/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15688 2 | 3 | import java.io.BufferedReader 4 | import java.io.BufferedWriter 5 | import java.io.InputStreamReader 6 | import java.io.OutputStreamWriter 7 | 8 | fun main() { 9 | val br = BufferedReader(InputStreamReader(System.`in`)) 10 | val counts = IntArray(size = 2_000_001) 11 | repeat(br.readLine().toInt()) { ++counts[br.readLine().toInt() + 1_000_000] } 12 | 13 | val sb = StringBuilder() 14 | counts.forEachIndexed { i, count -> repeat(count) { sb.appendLine(value = i - 1_000_000) } } 15 | 16 | val bw = BufferedWriter(OutputStreamWriter(System.out)) 17 | bw.write(sb.toString()) 18 | bw.flush() 19 | } 20 | -------------------------------------------------------------------------------- /src/boj_16172/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_16172 2 | 3 | fun main() { 4 | val s = readln() 5 | val k = readln() 6 | 7 | val plain = buildString { s.forEach { if (it !in '0'..'9') append(it) } } 8 | 9 | val failOf = IntArray(plain.length) 10 | var j = 0 11 | for (i in 1 until plain.length) { 12 | while (0 < j && plain[i] != plain[j]) j = failOf[j - 1] 13 | if (plain[i] == plain[j]) failOf[i] = ++j 14 | } 15 | 16 | j = 0 17 | for (i in plain.indices) { 18 | while (0 < j && plain[i] != k[j]) j = failOf[j - 1] 19 | if (plain[i] == k[j]) ++j 20 | if (j == k.length) return print(1) 21 | } 22 | 23 | print(0) 24 | } 25 | -------------------------------------------------------------------------------- /src/boj_18870/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_18870 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val st = StringTokenizer(readln()) 8 | val xs = IntArray(n) 9 | val set = HashSet() 10 | repeat(n) { 11 | val x = st.nextToken().toInt() 12 | xs[it] = x 13 | set.add(x) 14 | } 15 | 16 | val map = set.sortedDescending() 17 | .mapIndexed { idx, x -> x to set.size - idx - 1 } 18 | .toMap() 19 | val result = buildString { xs.forEach { x -> append(map[x], " ") } } 20 | 21 | System.out.bufferedWriter().use { 22 | it.write(result) 23 | it.flush() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/boj_2720/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2720 2 | 3 | fun main() { 4 | val changes = intArrayOf(25, 10, 5, 1) 5 | 6 | val result = buildString { 7 | repeat(readln().toInt()) { 8 | var money = readln().toInt() 9 | 10 | changes.forEach { change -> 11 | var count = 0 12 | while (change <= money) { 13 | money -= change 14 | ++count 15 | } 16 | append(count, " ") 17 | } 18 | appendLine() 19 | } 20 | } 21 | 22 | System.out.bufferedWriter().use { 23 | it.write(result) 24 | it.flush() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_3053/Main.java: -------------------------------------------------------------------------------- 1 | package boj_3053; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 3053번 (택시 기하학) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/3053 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int R = Integer.parseInt(br.readLine()); 17 | 18 | br.close(); 19 | 20 | // R 제곱을 구함 21 | double rSquare = Math.pow(R, 2); 22 | 23 | // 결과 값 출력 24 | System.out.printf("%.6f\n%.6f", rSquare * Math.PI, 2 * rSquare); 25 | } 26 | } -------------------------------------------------------------------------------- /src/boj_10872/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10872; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 10872번 (팩토리얼) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/10872 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String[] args) throws Exception { 14 | // 버퍼를 통해 입력을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int N = Integer.parseInt(br.readLine()); 17 | br.close(); 18 | 19 | // 팩토리얼을 계산 20 | int res = 1; 21 | 22 | for (int i = N; i >= 1; i--) { 23 | res *= i; 24 | } 25 | 26 | // 결과 값 출력 27 | System.out.println(res); 28 | } 29 | } -------------------------------------------------------------------------------- /src/boj_1182/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1182 2 | 3 | import java.util.StringTokenizer 4 | 5 | var s: Int = 0 6 | lateinit var nums: IntArray 7 | 8 | var subArrCount: Int = 0 9 | 10 | fun main() { 11 | var st = StringTokenizer(readln()) 12 | val n = st.nextToken().toInt() 13 | s = st.nextToken().toInt() 14 | 15 | st = StringTokenizer(readln()) 16 | nums = IntArray(n) { st.nextToken().toInt() } 17 | 18 | nums.forEachIndexed { i, num -> buildSubArr(i, num) } 19 | 20 | print(subArrCount) 21 | } 22 | 23 | fun buildSubArr(i: Int, sum: Int) { 24 | if (sum == s) ++subArrCount 25 | 26 | for (j in i + 1 until nums.size) buildSubArr(j, sum = sum + nums[j]) 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_12015/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_12015 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val st = StringTokenizer(readln()) 8 | 9 | val arr = IntArray(n) 10 | var lastIdx = -1 11 | while (st.hasMoreTokens()) { 12 | val a = st.nextToken().toInt() 13 | 14 | if (lastIdx < 0 || arr[lastIdx] < a) { 15 | arr[++lastIdx] = a 16 | continue 17 | } 18 | 19 | if (arr[lastIdx] == a) continue 20 | 21 | var idx = arr.binarySearch(a, toIndex = lastIdx + 1) 22 | if (idx < 0) idx = -idx - 1 23 | arr[idx] = a 24 | } 25 | 26 | println(lastIdx + 1) 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_14231/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14231 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | 9 | val st = StringTokenizer(readln()) 10 | val sizes = IntArray(n) 11 | val maxCounts = IntArray(n) 12 | var maxCount = 0 13 | repeat(n) { 14 | sizes[it] = st.nextToken().toInt() 15 | maxCounts[it] = 1 16 | for (i in 0..() 5 | repeat(readln().toInt()) { 6 | val name = readln() 7 | map[name] = map.getOrDefault(name, defaultValue = 0) + 1 8 | } 9 | 10 | var topName = "" 11 | var topCount = 0 12 | map.forEach { (name, count) -> 13 | when { 14 | topCount < count -> { 15 | topName = name 16 | topCount = count 17 | } 18 | 19 | topCount == count && name < topName -> { 20 | topName = name 21 | } 22 | 23 | else -> Unit 24 | } 25 | } 26 | 27 | print(topName) 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_19941/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_19941 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val k = st.nextToken().toInt() 9 | val str = readln() 10 | 11 | val isEaten = BooleanArray(n) 12 | var count = 0 13 | for (i in 0 until n) { 14 | val c = str[i] 15 | if (c == 'P') { 16 | for (j in i - k..i + k) { 17 | if (j < 0 || n <= j || isEaten[j] || str[j] == 'P') continue 18 | 19 | isEaten[j] = true 20 | ++count 21 | break 22 | } 23 | } 24 | } 25 | 26 | println(count) 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_2163/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2163; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 2163번 (초콜릿 자르기) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/2163 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 이용해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | br.close(); 19 | 20 | // 결과 값 출력 21 | System.out.println(Integer.parseInt(st.nextToken()) * Integer.parseInt(st.nextToken()) - 1); 22 | } 23 | } -------------------------------------------------------------------------------- /src/boj_3046/Main.java: -------------------------------------------------------------------------------- 1 | package boj_3046; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 3046번 (R2) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/3046 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 17 | br.close(); 18 | 19 | int R1 = Integer.parseInt(st.nextToken()); 20 | int S = Integer.parseInt(st.nextToken()); 21 | 22 | System.out.println(2 * S - R1); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /src/boj_4796/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_4796 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.min 5 | 6 | fun main() { 7 | val result = buildString { 8 | var case = 1 9 | while (true) { 10 | val st = StringTokenizer(readln()) 11 | val l = st.nextToken().toLong() 12 | val p = st.nextToken().toLong() 13 | val v = st.nextToken().toLong() 14 | if (l == 0L && p == 0L && v == 0L) break 15 | 16 | append("Case", " ", case++, ": ", v / p * l + min(a = v % p, l), "\n") 17 | } 18 | } 19 | 20 | System.out.bufferedWriter().use { 21 | it.write(result) 22 | it.flush() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/boj_11005/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11005 2 | 3 | import java.util.Stack 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | val st = StringTokenizer(readln()) 8 | var n = st.nextToken().toInt() 9 | val b = st.nextToken().toInt() 10 | 11 | val stack = Stack() 12 | while (0 <= n) { 13 | val quotient = n / b 14 | val remainder = n % b 15 | stack.push(remainder.toBaseChar()) 16 | n -= quotient * b 17 | } 18 | val result = buildString { while (stack.isNotEmpty()) append(stack.pop()) } 19 | 20 | println(result) 21 | } 22 | 23 | fun Int.toBaseChar(): Char = 24 | if (10 <= this) (this + 'A'.code - 10).toChar() else toChar() + '0'.code 25 | -------------------------------------------------------------------------------- /src/boj_2959/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2959; 2 | import java.util.Arrays; 3 | import java.util.Scanner; 4 | 5 | /** 6 | * 백준 온라인 저지 2959번 (거북이) 문제풀이 7 | * 8 | * @see https://www.acmicpc.net/problem/2959 9 | * @author devetude 10 | */ 11 | public class Main { 12 | public static void main(String args[]) throws Exception { 13 | // 입력 값을 받음 14 | Scanner sc = new Scanner(System.in); 15 | int[] inputs = new int[4]; 16 | 17 | for (int i = 0; i < 4; i++) { 18 | inputs[i] = sc.nextInt(); 19 | } 20 | 21 | sc.close(); 22 | 23 | // 입력 값 정렬 24 | Arrays.sort(inputs); 25 | 26 | // 결과 값 출력 (직사각형이나 정사각형을 만드는데 넓이를 결정 짓는 두 변은 가장 짧은 변과 두번째로 긴 변) 27 | System.out.println(inputs[0] * inputs[2]); 28 | } 29 | } -------------------------------------------------------------------------------- /src/boj_5565/Main.java: -------------------------------------------------------------------------------- 1 | package boj_5565; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 5565번 (영수증) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/5565 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int sum = Integer.parseInt(br.readLine()); 17 | 18 | // 10권의 합에서 나머지 9권의 가격을 뺌 19 | for (int i = 0; i < 9; i++) { 20 | sum -= Integer.parseInt(br.readLine()); 21 | } 22 | 23 | br.close(); 24 | 25 | // 결과 값 출력 26 | System.out.println(sum); 27 | } 28 | } -------------------------------------------------------------------------------- /src/boj_11568/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11568 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | val st = StringTokenizer(readln()) 9 | val nums = IntArray(n) 10 | repeat(n) { nums[it] = st.nextToken().toInt() } 11 | 12 | val maxLengths = IntArray(n) 13 | var maxLength = 0 14 | for (i in nums.indices) { 15 | maxLengths[i] = 1 16 | for (j in 0..() 12 | repeat(n) { list.add(it + 1) } 13 | 14 | val result = IntArray(n) 15 | var i = 0 16 | var j = 0 17 | while (list.isNotEmpty()) { 18 | i = (i + k - 1) % list.size 19 | result[j++] = list.removeAt(i) 20 | } 21 | 22 | System.out.bufferedWriter().use { 23 | it.write(result.joinToString(separator = ", ", prefix = "<", postfix = ">")) 24 | it.flush() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_18353/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_18353 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | val st = StringTokenizer(readln()) 9 | val powers = IntArray(size = n + 1) 10 | repeat(n) { powers[it + 1] = st.nextToken().toInt() } 11 | 12 | val maxSizes = IntArray(size = n + 1) 13 | var maxSize = 0 14 | for (i in 1..n) { 15 | maxSizes[i] = 1 16 | for (j in 1..>() 12 | repeat(n) { 13 | val height = st.nextToken().toInt() 14 | while (stack.isNotEmpty() && stack.peek().second <= height) stack.pop() 15 | append(if (stack.isNotEmpty()) stack.peek().first else 0, ' ') 16 | stack.push(it + 1 to height) 17 | } 18 | } 19 | 20 | System.out.bufferedWriter().use { 21 | it.write(result) 22 | it.flush() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/boj_2812/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2812 2 | 3 | import java.util.Stack 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | val st = StringTokenizer(readln()) 8 | val n = st.nextToken().toInt() 9 | val k = st.nextToken().toInt() 10 | val numberStr = readln() 11 | 12 | val stack = Stack() 13 | var removedCount = 0 14 | for (i in 0 until n) { 15 | val numberChar = numberStr[i] 16 | while (stack.isNotEmpty() && stack.peek() < numberChar && removedCount < k) { 17 | stack.pop() 18 | ++removedCount 19 | } 20 | 21 | stack.push(numberChar) 22 | } 23 | 24 | println(stack.subList(0, n - k).joinToString(separator = "")) 25 | } 26 | -------------------------------------------------------------------------------- /src/boj_2999/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2999 2 | 3 | import kotlin.math.sqrt 4 | 5 | fun main() { 6 | val m = readln() 7 | 8 | val n = m.length 9 | var r = 1 10 | var c = n 11 | for (i in sqrt(n.toDouble()).toInt() downTo 1) { 12 | r = i 13 | c = n / r 14 | if (r * c != n) continue 15 | if (r <= c) break 16 | } 17 | 18 | val matrix = Array(r) { CharArray(c) } 19 | var i = 0 20 | for (col in 0 until c) { 21 | for (row in 0 until r) matrix[row][col] = m[i++] 22 | } 23 | 24 | val sb = StringBuilder() 25 | for (row in 0 until r) { 26 | for (col in 0 until c) sb.append(matrix[row][col]) 27 | } 28 | 29 | print(sb.toString()) 30 | } 31 | -------------------------------------------------------------------------------- /src/boj_9063/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9063 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.abs 5 | 6 | fun main() { 7 | var minX = Int.MAX_VALUE 8 | var maxX = Int.MIN_VALUE 9 | var minY = Int.MAX_VALUE 10 | var maxY = Int.MIN_VALUE 11 | repeat(readln().toInt()) { 12 | val st = StringTokenizer(readln()) 13 | val x = st.nextToken().toInt() 14 | val y = st.nextToken().toInt() 15 | 16 | minX = minX.coerceAtMost(x) 17 | maxX = maxX.coerceAtLeast(x) 18 | minY = minY.coerceAtMost(y) 19 | maxY = maxY.coerceAtLeast(y) 20 | } 21 | 22 | val dX = abs(n = maxX - minX) 23 | val dY = abs(n = maxY - minY) 24 | 25 | println(dX * dY) 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_11720/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11720; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 11720번 (숫자의 합) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/11720 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 이용해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | br.readLine(); 17 | char[] numChars = br.readLine().toCharArray(); 18 | int sum = 0; 19 | 20 | for (char numChar : numChars) { 21 | sum += Character.getNumericValue(numChar); 22 | } 23 | 24 | br.close(); 25 | 26 | // 결과 값 출력 27 | System.out.println(sum); 28 | } 29 | } -------------------------------------------------------------------------------- /src/boj_13300/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13300 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val k = st.nextToken().toInt() 9 | 10 | val counts = Array(size = 7) { IntArray(size = 2) } 11 | repeat(n) { 12 | st = StringTokenizer(readln()) 13 | val s = st.nextToken().toInt() 14 | val y = st.nextToken().toInt() 15 | ++counts[y][s] 16 | } 17 | val requiredMinRoomCount = counts.sumOf { countsByGrade -> 18 | countsByGrade.sumOf { countOfSex -> 19 | countOfSex / k + if (countOfSex % k == 0) 0 else 1 20 | } 21 | } 22 | 23 | print(requiredMinRoomCount) 24 | } 25 | -------------------------------------------------------------------------------- /src/boj_2445/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2445 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | 6 | System.out.bufferedWriter().use { bw -> 7 | for (i in 1 until n) { 8 | repeat(i) { bw.write("*") } 9 | repeat(times = n - i shl 1) { bw.write(" ") } 10 | repeat(i) { bw.write("*") } 11 | bw.write("\n") 12 | } 13 | repeat(times = n shl 1) { bw.write("*") } 14 | bw.write("\n") 15 | for (i in n - 1 downTo 1) { 16 | repeat(i) { bw.write("*") } 17 | repeat(times = n - i shl 1) { bw.write(" ") } 18 | repeat(i) { bw.write("*") } 19 | bw.write("\n") 20 | } 21 | bw.flush() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_25214/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_25214 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | import kotlin.math.min 6 | 7 | fun main() { 8 | val n = readln().toInt() 9 | val st = StringTokenizer(readln()) 10 | 11 | val maxDiffs = IntArray(n) 12 | var minValue = st.nextToken().toInt() 13 | for (i in 1 until n) { 14 | val num = st.nextToken().toInt() 15 | maxDiffs[i] = max(maxDiffs[i - 1], b = num - minValue) 16 | minValue = min(minValue, num) 17 | } 18 | 19 | System.out.bufferedWriter().use { bw -> 20 | maxDiffs.forEach { 21 | bw.write(it.toString()) 22 | bw.write(" ") 23 | } 24 | 25 | bw.flush() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_9375/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9375 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val sb = StringBuilder() 7 | repeat(readln().toInt()) { 8 | val map = HashMap() 9 | repeat(readln().toInt()) { 10 | val st = StringTokenizer(readln()) 11 | st.nextToken() 12 | val type = st.nextToken() 13 | map[type] = map.getOrDefault(type, defaultValue = 0) + 1 14 | } 15 | val combination = map.values.fold(initial = 1) { acc, size -> acc * (size + 1) } - 1 16 | sb.appendLine(combination) 17 | } 18 | 19 | System.out.bufferedWriter().use { 20 | it.write(sb.toString()) 21 | it.flush() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_2914/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2914; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 2914번 (저작권) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/2914 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | int A = Integer.parseInt(st.nextToken()); 19 | int I = Integer.parseInt(st.nextToken()); 20 | br.close(); 21 | 22 | // 결과 값 출력 23 | System.out.println(A * (I - 1) + 1); 24 | } 25 | } -------------------------------------------------------------------------------- /src/boj_22971/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_22971 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val st = StringTokenizer(readln()) 9 | val nums = IntArray(n) 10 | val counts = IntArray(n) { 1 } 11 | System.out.bufferedWriter().use { bw -> 12 | repeat(n) { 13 | nums[it] = st.nextToken().toInt() 14 | for (i in 0..() 12 | var rank = 1 13 | repeat(n) { 14 | while (stack.isNotEmpty() && stack.peek() == rank) { 15 | stack.pop() 16 | ++rank 17 | } 18 | val next = st.nextToken().toInt() 19 | if (next == rank) ++rank else stack.push(next) 20 | } 21 | while (stack.isNotEmpty() && stack.peek() == rank) { 22 | stack.pop() 23 | ++rank 24 | } 25 | 26 | println(if (stack.isEmpty()) "Nice" else "Sad") 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_5086/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_5086 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val results = buildString { 7 | while (true) { 8 | val st = StringTokenizer(readln()) 9 | val first = st.nextToken().toInt() 10 | val second = st.nextToken().toInt() 11 | 12 | val result = when { 13 | first == 0 && second == 0 -> break 14 | second % first == 0 -> "factor" 15 | first % second == 0 -> "multiple" 16 | else -> "neither" 17 | } 18 | appendLine(result) 19 | } 20 | } 21 | 22 | System.out.bufferedWriter().use { 23 | it.write(results) 24 | it.flush() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_15651/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15651 2 | 3 | import java.util.StringTokenizer 4 | 5 | val sb = StringBuilder() 6 | 7 | fun main() { 8 | val st = StringTokenizer(readln()) 9 | val n = st.nextToken().toInt() 10 | val m = st.nextToken().toInt() 11 | 12 | val arr = IntArray(m) 13 | dfs(n, arr) 14 | 15 | System.out.bufferedWriter().use { 16 | it.write(sb.toString()) 17 | it.flush() 18 | } 19 | } 20 | 21 | fun dfs(n: Int, arr: IntArray, depth: Int = 0) { 22 | if (depth == arr.size) { 23 | arr.forEach { sb.append(it, " ") } 24 | sb.appendLine() 25 | return 26 | } 27 | 28 | for (idx in 1..n) { 29 | arr[depth] = idx 30 | dfs(n, arr, depth = depth + 1) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/boj_2902/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2902; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 2902번 (KMP는 왜 KMP일까?) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/2902 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | String[] strs = br.readLine().split("-"); 17 | 18 | br.close(); 19 | 20 | // 버퍼를 통해 결과 값을 만듬 21 | StringBuilder sb = new StringBuilder(); 22 | 23 | for (String str : strs) { 24 | sb.append(str.charAt(0)); 25 | } 26 | 27 | // 결과 값 한꺼번에 출력 28 | System.out.println(sb.toString()); 29 | } 30 | } -------------------------------------------------------------------------------- /src/boj_13975/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13975 2 | 3 | import java.util.PriorityQueue 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | val sb = StringBuilder() 8 | repeat(readln().toInt()) { 9 | val k = readln().toInt() 10 | val st = StringTokenizer(readln()) 11 | val pq = PriorityQueue() 12 | repeat(k) { pq.offer(st.nextToken().toLong()) } 13 | 14 | var totalCost = 0L 15 | while (1 < pq.size) { 16 | val cost = pq.poll() + pq.poll() 17 | totalCost += cost 18 | pq.offer(cost) 19 | } 20 | sb.appendLine(totalCost) 21 | } 22 | 23 | System.out.bufferedWriter().use { 24 | it.write(sb.toString()) 25 | it.flush() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_17298/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_17298 2 | 3 | import java.util.Stack 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | val st = StringTokenizer(readln()) 9 | val numbers = IntArray(n) 10 | repeat(n) { numbers[it] = st.nextToken().toInt() } 11 | 12 | val idxStack = Stack() 13 | for (i in numbers.indices) { 14 | while (idxStack.isNotEmpty() && numbers[idxStack.peek()] < numbers[i]) 15 | numbers[idxStack.pop()] = numbers[i] 16 | idxStack.push(i) 17 | } 18 | while (idxStack.isNotEmpty()) numbers[idxStack.pop()] = -1 19 | 20 | System.out.bufferedWriter().use { 21 | it.write(numbers.joinToString(separator = " ")) 22 | it.flush() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/boj_2921/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2921; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 2921번 (도미노) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/2921 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int N = Integer.parseInt(br.readLine()); 17 | br.close(); 18 | 19 | // 결과 저장 변수 20 | int res = 0; 21 | 22 | // i가 0부터 N까지 커지면서 첫항이 i 끝항이 (2 * i) 공차가 1인 등차수열의 합들의 합을 구함 23 | for (int i = 0; i <= N; i++) { 24 | res += 3 * i * (i + 1) / 2; 25 | } 26 | 27 | // 결과 값 출력 28 | System.out.println(res); 29 | } 30 | } -------------------------------------------------------------------------------- /src/boj_10816/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10816 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | var st = StringTokenizer(readln()) 8 | val map = HashMap() 9 | repeat(n) { 10 | val number = st.nextToken().toInt() 11 | val count = map.getOrDefault(number, 0) 12 | map[number] = count + 1 13 | } 14 | 15 | val m = readln().toInt() 16 | st = StringTokenizer(readln()) 17 | val result = buildString { 18 | repeat(m) { 19 | val number = st.nextToken().toInt() 20 | append(map.getOrDefault(number, 0), " ") 21 | } 22 | } 23 | 24 | System.out.bufferedWriter().use { 25 | it.write(result) 26 | it.flush() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_2156/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2156 2 | 3 | import kotlin.math.max 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val quantities = IntArray(size = n + 1) 8 | repeat(n) { quantities[it + 1] = readln().toInt() } 9 | if (n == 1) return println(quantities[1]) 10 | 11 | val maxQuantities = IntArray(size = n + 1) 12 | maxQuantities[1] = quantities[1] 13 | maxQuantities[2] = quantities[1] + quantities[2] 14 | 15 | for (i in 3..n) { 16 | val case1 = maxQuantities[i - 2] + quantities[i] 17 | val case2 = maxQuantities[i - 1] 18 | val case3 = maxQuantities[i - 3] + quantities[i - 1] + quantities[i] 19 | maxQuantities[i] = max(case1, max(case2, case3)) 20 | } 21 | 22 | println(maxQuantities[n]) 23 | } 24 | -------------------------------------------------------------------------------- /src/boj_9012/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9012 2 | 3 | import java.util.Stack 4 | 5 | fun main() { 6 | val result = buildString { 7 | repeat(readln().toInt()) { 8 | val stack = Stack() 9 | mainLoop@ for (c in readln()) { 10 | if (c == '(') { 11 | stack.push(c) 12 | continue 13 | } 14 | 15 | while (stack.isNotEmpty()) if (stack.pop() == '(') continue@mainLoop 16 | 17 | stack.push(c) 18 | break 19 | } 20 | appendLine(if (stack.isEmpty()) "YES" else "NO") 21 | } 22 | } 23 | 24 | System.out.bufferedWriter().use { 25 | it.write(result) 26 | it.flush() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_10811/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_10811 2 | 3 | fun main() { 4 | val (n, m) = readln().split(" ").map { it.toInt() } 5 | 6 | val buckets = MutableList(size = n + 1) { it } 7 | repeat(m) { 8 | var (i, j) = readln().split(" ").map { it.toInt() } 9 | while (i < j) { 10 | val temp = buckets[i] 11 | buckets[i] = buckets[j] 12 | buckets[j] = temp 13 | ++i 14 | --j 15 | } 16 | } 17 | val result = buildString { 18 | for (idx in 1 until buckets.size - 1) { 19 | append(buckets[idx], " ") 20 | } 21 | append(buckets.last()) 22 | } 23 | 24 | System.out.bufferedWriter().use { 25 | it.write(result) 26 | it.flush() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_1477/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1477 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | val l = st.nextToken().toInt() 10 | 11 | st = StringTokenizer(readln()) 12 | val x = IntArray(size = n + 2) 13 | x[0] = 0 14 | repeat(n) { x[it + 1] = st.nextToken().toInt() } 15 | x[n + 1] = l 16 | x.sort() 17 | 18 | var low = 1 19 | var high = l - 1 20 | while (low < high) { 21 | val mid = low + high shr 1 22 | var count = 0 23 | for (i in 1 until x.size) count += (x[i] - x[i - 1] - 1) / mid 24 | if (m < count) low = mid + 1 else high = mid 25 | } 26 | 27 | print(high) 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_10822/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10822; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 10822번 (더하기) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/10822 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), ","); 18 | int sum = 0; 19 | 20 | // 입력 값들의 합을 구함 21 | while (st.hasMoreTokens()) { 22 | sum += Integer.parseInt(st.nextToken()); 23 | } 24 | 25 | br.close(); 26 | 27 | // 결과 값 출력 28 | System.out.println(sum); 29 | } 30 | } -------------------------------------------------------------------------------- /src/boj_11023/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11023; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 11023번 (더하기 3) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/11023 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | int sum = 0; 19 | 20 | // 입력 값들의 합을 구함 21 | while (st.hasMoreTokens()) { 22 | sum += Integer.parseInt(st.nextToken()); 23 | } 24 | 25 | br.close(); 26 | 27 | // 결과 값 출력 28 | System.out.println(sum); 29 | } 30 | } -------------------------------------------------------------------------------- /src/boj_4097/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_4097 2 | 3 | import kotlin.math.max 4 | 5 | fun main() { 6 | System.out.bufferedWriter().use { 7 | while (true) { 8 | val n = readln().toInt() 9 | if (n == 0) return it.flush() 10 | 11 | var yesterdayMaxProfit = 0L 12 | var maxProfit = Long.MIN_VALUE 13 | for (day in 1..n) { 14 | val todayProfit = readln().toLong() 15 | val todayMaxProfit = max(a = yesterdayMaxProfit + todayProfit, todayProfit) 16 | yesterdayMaxProfit = todayMaxProfit 17 | maxProfit = max(maxProfit, todayMaxProfit) 18 | } 19 | 20 | it.write(maxProfit.toString()) 21 | it.write("\n") 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/boj_10757/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10757; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.math.BigInteger; 6 | import java.util.StringTokenizer; 7 | 8 | /** 9 | * 백준 온라인 저지 10757번 (큰 수 A+B) 문제풀이 10 | * 11 | * @see https://www.acmicpc.net/problem/10757 12 | * @author devetude 13 | */ 14 | public class Main { 15 | public static void main(String[] args) throws Exception { 16 | // 버퍼를 이용해 입력을 받음 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 19 | br.close(); 20 | 21 | BigInteger A = new BigInteger(st.nextToken()); 22 | BigInteger B = new BigInteger(st.nextToken()); 23 | 24 | // 결과 값 출력 25 | System.out.println(A.add(B)); 26 | } 27 | } -------------------------------------------------------------------------------- /src/boj_11652/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11652 2 | 3 | import java.io.BufferedReader 4 | import java.io.InputStreamReader 5 | 6 | fun main() { 7 | val br = BufferedReader(InputStreamReader(System.`in`)) 8 | val n = br.readLine().toInt() 9 | val arr = LongArray(n) { br.readLine().toLong() }.apply { sort() } 10 | 11 | var num = arr[0] 12 | var maxCountNum = num 13 | var count = 1 14 | var maxCount = count 15 | for (i in 1 until n) { 16 | if (num == arr[i]) { 17 | ++count 18 | if (maxCount < count) { 19 | maxCount = count 20 | maxCountNum = num 21 | } 22 | continue 23 | } 24 | 25 | num = arr[i] 26 | count = 1 27 | } 28 | 29 | print(maxCountNum) 30 | } 31 | -------------------------------------------------------------------------------- /src/boj_11718/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11718; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 11718번 (그대로 출력하기) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/11718 10 | * @author devetude 11 | */ 12 | public class Main { 13 | private static final String NEW_LINE = "\n"; 14 | 15 | public static void main(String args[]) throws Exception { 16 | // 버퍼를 통해 입력 값을 받음 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | StringBuilder sb = new StringBuilder(); 19 | String line = null; 20 | 21 | while ((line = br.readLine()) != null) { 22 | sb.append(line).append(NEW_LINE); 23 | } 24 | 25 | br.close(); 26 | 27 | // 버퍼를 통해 결과 값 한꺼번에 출력 28 | System.out.println(sb.toString()); 29 | } 30 | } -------------------------------------------------------------------------------- /src/boj_13305/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_13305 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.min 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | 9 | var st = StringTokenizer(readln()) 10 | val distances = IntArray(size = n - 1) 11 | repeat(distances.size) { distances[it] = st.nextToken().toInt() } 12 | 13 | st = StringTokenizer(readln()) 14 | val costs = IntArray(n) 15 | repeat(n) { costs[it] = st.nextToken().toInt() } 16 | 17 | var minCost = costs.first() 18 | var totalCost = minCost.toLong() * distances.first() 19 | for (i in 1 until costs.lastIndex) { 20 | val cost = costs[i] 21 | minCost = min(minCost, cost) 22 | totalCost += minCost.toLong() * distances[i] 23 | } 24 | 25 | println(totalCost) 26 | } 27 | -------------------------------------------------------------------------------- /src/boj_2003/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2003 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | st = StringTokenizer(readln()) 11 | var acc = 0 12 | val subSums = IntArray(n) { acc += st.nextToken().toInt(); acc } 13 | 14 | var left = 0 15 | var right = 0 16 | var count = 0 17 | while (left < n && right < n) { 18 | val sum = subSums[right] - if (0 < left) subSums[left - 1] else 0 19 | if (sum < m) { 20 | ++right 21 | } else { 22 | ++left 23 | if (right < left) right = left 24 | if (sum == m) ++count 25 | } 26 | } 27 | 28 | print(count) 29 | } 30 | -------------------------------------------------------------------------------- /src/boj_2010/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2010; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 2010번 (플러그) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/2010 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int N = Integer.parseInt(br.readLine()); 17 | int totalCounts = 1; 18 | 19 | for (int i = 0; i < N; i++) { 20 | // 현재까지 가능한 플러그 + 새롭게 추가되는 플러스 - 자기자신을 끼우는 플러그 (1) = 전체 플러그 수 21 | totalCounts += Integer.parseInt(br.readLine()) - 1; 22 | } 23 | 24 | br.close(); 25 | 26 | // 결과 값 출력 27 | System.out.println(totalCounts); 28 | } 29 | } -------------------------------------------------------------------------------- /src/boj_11719/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11719; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 11719번 (그대로 출력하기 2) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/11719 10 | * @author devetude 11 | */ 12 | public class Main { 13 | private static final String NEW_LINE = "\n"; 14 | 15 | public static void main(String args[]) throws Exception { 16 | // 버퍼를 통해 입력 값을 받음 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | StringBuilder sb = new StringBuilder(); 19 | String line = null; 20 | 21 | while ((line = br.readLine()) != null) { 22 | sb.append(line).append(NEW_LINE); 23 | } 24 | 25 | br.close(); 26 | 27 | // 버퍼를 통해 결과 값 한꺼번에 출력 28 | System.out.println(sb.toString()); 29 | } 30 | } -------------------------------------------------------------------------------- /src/boj_2870/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2870 2 | 3 | import java.math.BigInteger 4 | import java.util.LinkedList 5 | 6 | fun main() { 7 | val nums = LinkedList() 8 | repeat(readln().toInt()) { 9 | val sb = StringBuilder() 10 | readln().forEach { 11 | if (it in '0'..'9') { 12 | sb.append(it) 13 | return@forEach 14 | } 15 | if (sb.isEmpty()) return@forEach 16 | 17 | nums.add(BigInteger(sb.toString())) 18 | sb.clear() 19 | } 20 | if (sb.isNotEmpty()) nums.add(BigInteger(sb.toString())) 21 | } 22 | nums.sort() 23 | 24 | System.out.bufferedWriter().use { 25 | it.write(nums.joinToString(separator = "\n")) 26 | it.flush() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_9935/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9935 2 | 3 | fun main() { 4 | val str = readln() 5 | val boomStr = readln() 6 | 7 | val sb = StringBuilder() 8 | str.forEach { 9 | sb.append(it) 10 | 11 | val startIdx = sb.length - boomStr.length 12 | if (startIdx < 0) return@forEach 13 | 14 | var shouldDelete = true 15 | for (i in boomStr.indices) { 16 | if (sb[startIdx + i] == boomStr[i]) continue 17 | 18 | shouldDelete = false 19 | break 20 | } 21 | 22 | if (shouldDelete) sb.deleteRange(startIdx, sb.length) 23 | } 24 | val result = if (sb.isEmpty()) "FRULA" else sb.toString() 25 | 26 | System.out.bufferedWriter().use { 27 | it.write(result) 28 | it.flush() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/boj_15652/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15652 2 | 3 | import java.util.StringTokenizer 4 | 5 | val sb = StringBuilder() 6 | 7 | fun main() { 8 | val st = StringTokenizer(readln()) 9 | val n = st.nextToken().toInt() 10 | val m = st.nextToken().toInt() 11 | 12 | val arr = IntArray(m) 13 | dfs(n, arr) 14 | 15 | System.out.bufferedWriter().use { 16 | it.write(sb.toString()) 17 | it.flush() 18 | } 19 | } 20 | 21 | fun dfs(n: Int, arr: IntArray, startIdx: Int = 1, depth: Int = 0) { 22 | if (depth == arr.size) { 23 | arr.forEach { sb.append(it, " ") } 24 | sb.appendLine() 25 | return 26 | } 27 | 28 | for (idx in startIdx..n) { 29 | arr[depth] = idx 30 | dfs(n, arr, startIdx = idx, depth = depth + 1) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/boj_11729/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11729 2 | 3 | var count: Int = 0 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val moveBuilder = StringBuilder() 9 | move(n, moveBuilder, from = 1, to = 3, tmp = 2) 10 | 11 | System.out.bufferedWriter().use { 12 | it.write(count.toString()) 13 | it.write("\n") 14 | it.write(moveBuilder.toString()) 15 | it.flush() 16 | } 17 | } 18 | 19 | fun move(n: Int, moveBuilder: StringBuilder, from: Int, to: Int, tmp: Int) { 20 | if (n == 1) { 21 | ++count 22 | moveBuilder.append(from, ' ').appendLine(to) 23 | return 24 | } 25 | 26 | move(n = n - 1, moveBuilder, from, tmp, to) 27 | move(n = 1, moveBuilder, from, to, tmp) 28 | move(n = n - 1, moveBuilder, tmp, to, from) 29 | } 30 | -------------------------------------------------------------------------------- /src/boj_15650/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15650 2 | 3 | import java.util.StringTokenizer 4 | 5 | val sb = StringBuilder() 6 | 7 | fun main() { 8 | val st = StringTokenizer(readln()) 9 | val n = st.nextToken().toInt() 10 | val m = st.nextToken().toInt() 11 | 12 | val arr = IntArray(m) 13 | dfs(n, arr) 14 | 15 | System.out.bufferedWriter().use { 16 | it.write(sb.toString()) 17 | it.flush() 18 | } 19 | } 20 | 21 | fun dfs(n: Int, arr: IntArray, startIdx: Int = 1, depth: Int = 0) { 22 | if (depth == arr.size) { 23 | arr.forEach { sb.append(it, " ") } 24 | sb.appendLine() 25 | return 26 | } 27 | 28 | for (idx in startIdx..n) { 29 | arr[depth] = idx 30 | dfs(n, arr, startIdx = idx + 1, depth = depth + 1) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/boj_19583/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_19583 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val s = st.nextToken() 8 | val e = st.nextToken() 9 | val q = st.nextToken() 10 | 11 | val before = HashSet() 12 | val after = HashSet() 13 | var line = "" 14 | while (readlnOrNull()?.also { line = it } != null) { 15 | st = StringTokenizer(line) 16 | val time = st.nextToken() 17 | val nickname = st.nextToken() 18 | when { 19 | time <= s -> before.add(nickname) 20 | time in e..q -> after.add(nickname) 21 | else -> Unit 22 | } 23 | } 24 | 25 | var count = 0 26 | before.forEach { if (it in after) ++count } 27 | print(count) 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_13277/Main.java: -------------------------------------------------------------------------------- 1 | package boj_13277; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.math.BigDecimal; 6 | import java.util.StringTokenizer; 7 | 8 | /** 9 | * 백준 온라인 저지 13277번 (큰 수 곱셈) 문제풀이 10 | * 11 | * @see https://www.acmicpc.net/problem/13277 12 | * @author devetude 13 | */ 14 | public class Main { 15 | public static void main(String args[]) throws Exception { 16 | // 버퍼를 통해 입력 값을 받음 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 19 | 20 | br.close(); 21 | 22 | BigDecimal A = new BigDecimal(st.nextToken()); 23 | BigDecimal B = new BigDecimal(st.nextToken()); 24 | 25 | // 결과 값 출력 26 | System.out.println(A.multiply(B).toString()); 27 | } 28 | } -------------------------------------------------------------------------------- /src/boj_2738/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2738 2 | 3 | fun main() { 4 | val (n, m) = readln().split(" ").map { it.toInt() } 5 | 6 | val aMatrix = MutableList>(size = n) { emptyList() } 7 | repeat(n) { row -> aMatrix[row] = readln().split(" ").map { it.toInt() } } 8 | 9 | val bMatrix = MutableList>(size = n) { emptyList() } 10 | repeat(n) { row -> bMatrix[row] = readln().split(" ").map { it.toInt() } } 11 | 12 | val result = buildString { 13 | for (row in 0 until n) { 14 | for (col in 0 until m) { 15 | append(aMatrix[row][col] + bMatrix[row][col], " ") 16 | } 17 | } 18 | appendLine() 19 | } 20 | 21 | System.out.bufferedWriter().use { 22 | it.write(result) 23 | it.flush() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/boj_2828/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2828 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | val j = readln().toInt() 10 | 11 | var start = 1 12 | var minMoves = 0 13 | repeat(j) { 14 | val x = readln().toInt() 15 | val end = start + m - 1 16 | when { 17 | x < start -> { 18 | minMoves += start - x 19 | start = x 20 | } 21 | 22 | end < x -> { 23 | val moves = x - end 24 | minMoves += moves 25 | start += moves 26 | } 27 | 28 | else -> Unit 29 | } 30 | } 31 | 32 | println(minMoves) 33 | } 34 | -------------------------------------------------------------------------------- /src/boj_5347/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_5347 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val sb = StringBuilder() 7 | repeat(readln().toInt()) { 8 | val st = StringTokenizer(readln()) 9 | val a = st.nextToken().toLong() 10 | val b = st.nextToken().toLong() 11 | sb.appendLine(lcm(a, b)) 12 | } 13 | 14 | System.out.bufferedWriter().use { 15 | it.write(sb.toString()) 16 | it.flush() 17 | } 18 | } 19 | 20 | fun lcm(a: Long, b: Long): Long = a * b / gcd(maxOf(a, b), minOf(a, b)) 21 | 22 | fun gcd(max: Long, min: Long): Long { 23 | var a = max 24 | var b = min 25 | while (true) { 26 | val r = a % b 27 | if (r == 0L) break 28 | 29 | a = b 30 | b = r 31 | } 32 | 33 | return b 34 | } 35 | -------------------------------------------------------------------------------- /src/boj_8320/Main.java: -------------------------------------------------------------------------------- 1 | package boj_8320; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 8320번 (직사각형을 만드는 방법) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/8320 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int n = Integer.parseInt(br.readLine()); 17 | br.close(); 18 | 19 | // 만들 수 있는 직사각형 갯수 변수 저장 변수 20 | int cnt = 0; 21 | 22 | // 루프를 돌며 한 변의 길이가 1부터 n까지 가능한 직사각형의 갯수를 셈 23 | for (int i = 1; i <= n; i++) { 24 | for (int j = i; i * j <= n; j++) { 25 | cnt++; 26 | } 27 | } 28 | 29 | // 결과 값 출력 30 | System.out.println(cnt); 31 | } 32 | } -------------------------------------------------------------------------------- /src/boj_1152/Main.java: -------------------------------------------------------------------------------- 1 | package boj_1152; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 1152번 (단어의 개수) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/1152 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | 17 | // 단어를 추출 (문장 앞 뒷 공백제거 -> 여러개의 공백을 1개의 띄어쓰기로 변환 -> 띄어쓰기로 단어 분리) 18 | String[] wordStrs = br.readLine().trim().replaceAll("\\s+", " ").split(" "); 19 | 20 | br.close(); 21 | 22 | // 공백 단어인 경우 0 출력 23 | if (wordStrs[0].length() == 0) { 24 | System.out.println(0); 25 | } 26 | 27 | else { 28 | System.out.println(wordStrs.length); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/boj_11659/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11659 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | st = StringTokenizer(readln()) 11 | var acc = 0 12 | val subSums = IntArray(n) { acc += st.nextToken().toInt(); acc } 13 | 14 | val result = buildString { 15 | repeat(m) { 16 | st = StringTokenizer(readln()) 17 | val i = st.nextToken().toInt() 18 | val j = st.nextToken().toInt() 19 | val sum = subSums[j - 1] - if (1 < i) subSums[i - 2] else 0 20 | appendLine(sum) 21 | } 22 | } 23 | 24 | System.out.bufferedWriter().use { 25 | it.write(result) 26 | it.flush() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_24511/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_24511 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | val aSt = StringTokenizer(readln()) 8 | val bSt = StringTokenizer(readln()) 9 | val dequeue = ArrayDeque(n) 10 | repeat(n) { 11 | val a = aSt.nextToken() 12 | val b = bSt.nextToken() 13 | if (a == "0") dequeue.addFirst(b) 14 | } 15 | val m = readln().toInt() 16 | val cSt = StringTokenizer(readln()) 17 | repeat(times = m - dequeue.size) { 18 | val c = cSt.nextToken() 19 | dequeue.addLast(c) 20 | } 21 | val result = dequeue.joinToString(separator = " ", limit = m, truncated = "") 22 | 23 | System.out.bufferedWriter().use { 24 | it.write(result) 25 | it.flush() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_9663/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_9663 2 | 3 | import kotlin.math.abs 4 | 5 | var cases = 0 6 | 7 | fun main() { 8 | val n = readln().toInt() 9 | 10 | val cols = IntArray(n) 11 | dfs(cols) 12 | 13 | println(cases) 14 | } 15 | 16 | fun dfs(cols: IntArray, row: Int = 0) { 17 | if (row == cols.size) { 18 | ++cases 19 | return 20 | } 21 | 22 | for (col in cols.indices) { 23 | cols[row] = col 24 | if (isPromising(cols, row)) { 25 | dfs(cols, row = row + 1) 26 | } 27 | } 28 | } 29 | 30 | fun isPromising(cols: IntArray, row: Int): Boolean { 31 | for (i in 0 until row) { 32 | if (cols[row] == cols[i]) return false 33 | if (row - i == abs(n = cols[row] - cols[i])) return false 34 | } 35 | 36 | return true 37 | } 38 | -------------------------------------------------------------------------------- /src/boj_10988/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10988; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 10988번 (팰린드롬인지 확인하기) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/10988 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | char[] chars = br.readLine().toCharArray(); 17 | 18 | br.close(); 19 | 20 | int last = chars.length / 2; 21 | 22 | for (int i = 0; i < last; i++) { 23 | // 팰린드롬이 아닌 경우 24 | if (chars[i] != chars[chars.length - i - 1]) { 25 | System.out.println(0); 26 | 27 | return; 28 | } 29 | } 30 | 31 | // 팰린드롬인 경우 32 | System.out.println(1); 33 | } 34 | } -------------------------------------------------------------------------------- /src/boj_1620/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1620 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | val nameOf = Array(size = n + 1) { "" } 11 | val numOf = HashMap() 12 | repeat(n) { 13 | val num = it + 1 14 | val name = readln() 15 | nameOf[num] = name 16 | numOf[name] = num 17 | } 18 | 19 | val sb = StringBuilder() 20 | repeat(m) { 21 | val input = readln() 22 | val result = if (input[0] in '1'..'9') nameOf[input.toInt()] else numOf[input] 23 | sb.appendLine(result) 24 | } 25 | 26 | System.out.bufferedWriter().use { 27 | it.write(sb.toString()) 28 | it.flush() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/boj_21314/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_21314 2 | 3 | fun main() { 4 | val maxBuilder = StringBuilder() 5 | val minBuilder = StringBuilder() 6 | var m = 0 7 | readln().forEach { c -> 8 | if (c == 'K') { 9 | maxBuilder.append(5) 10 | repeat(m) { maxBuilder.append(0) } 11 | 12 | if (0 < m) minBuilder.append(1) 13 | repeat(times = m - 1) { minBuilder.append(0) } 14 | minBuilder.append(5) 15 | 16 | m = 0 17 | } else { 18 | ++m 19 | } 20 | } 21 | 22 | if (0 < m) { 23 | repeat(m) { maxBuilder.append(1) } 24 | 25 | minBuilder.append(1) 26 | repeat(times = m - 1) { minBuilder.append(0) } 27 | } 28 | 29 | println(maxBuilder.toString()) 30 | print(minBuilder.toString()) 31 | } 32 | -------------------------------------------------------------------------------- /src/boj_15489/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15489 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val r = st.nextToken().toInt() 8 | val c = st.nextToken().toInt() 9 | val w = st.nextToken().toInt() 10 | 11 | val values = Array(size = r + w) { row -> 12 | IntArray(size = row + 1) { col -> 13 | if (col == 1 || col == row) 1 else 0 14 | } 15 | } 16 | 17 | for (row in 3 until values.size) { 18 | for (col in 2.. 10 | repeat(t) { 11 | val n = readln().toInt() 12 | val st = StringTokenizer(readln()) 13 | 14 | val memory = IntArray(n) 15 | memory[0] = st.nextToken().toInt() 16 | var maxSum = memory[0] 17 | for (i in 1 until n) { 18 | val num = st.nextToken().toInt() 19 | memory[i] = max(num, b = memory[i - 1] + num) 20 | maxSum = max(maxSum, memory[i]) 21 | } 22 | 23 | bw.write(maxSum.toString()) 24 | bw.write("\n") 25 | } 26 | 27 | bw.flush() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/boj_10827/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10827; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.math.BigDecimal; 6 | import java.util.StringTokenizer; 7 | 8 | /** 9 | * 백준 온라인 저지 10827번 (a^b) 문제풀이 10 | * 11 | * @see https://www.acmicpc.net/problem/10827 12 | * @author devetude 13 | */ 14 | public class Main { 15 | public static void main(String[] args) throws Exception { 16 | // 버퍼를 이용해 입력을 받음 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 19 | br.close(); 20 | 21 | BigDecimal a = new BigDecimal(st.nextToken()); 22 | int b = Integer.parseInt(st.nextToken()); 23 | 24 | // 결과 값 출력 (지수승의 형태로 나오는 것을 방지하기 위해 toPlainString() 메소드 사용) 25 | System.out.println(a.pow(b).toPlainString()); 26 | } 27 | } -------------------------------------------------------------------------------- /src/boj_1655/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1655 2 | 3 | import java.util.PriorityQueue 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val minHeap = PriorityQueue(n) 9 | val maxHeap = PriorityQueue(n, reverseOrder()) 10 | val sb = StringBuilder() 11 | repeat(n) { 12 | val num = readln().toShort() 13 | val heap = if (minHeap.size == maxHeap.size) maxHeap else minHeap 14 | heap.offer(num) 15 | 16 | if (minHeap.isNotEmpty() && minHeap.peek() < maxHeap.peek()) { 17 | val tmp = minHeap.poll() 18 | minHeap.offer(maxHeap.poll()) 19 | maxHeap.offer(tmp) 20 | } 21 | 22 | sb.appendLine(maxHeap.peek()) 23 | } 24 | 25 | System.out.bufferedWriter().use { 26 | it.write(sb.toString()) 27 | it.flush() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/boj_1822/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1822 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val nA = st.nextToken().toInt() 8 | val nB = st.nextToken().toInt() 9 | 10 | st = StringTokenizer(readln()) 11 | val aArr = IntArray(nA) { st.nextToken().toInt() }.apply { sort() } 12 | 13 | st = StringTokenizer(readln()) 14 | val bSet = HashSet() 15 | repeat(nB) { bSet.add(st.nextToken().toInt()) } 16 | 17 | var size = 0 18 | val sb = StringBuilder("\n") 19 | aArr.forEach { 20 | if (it !in bSet) { 21 | ++size 22 | sb.append(it, ' ') 23 | } 24 | } 25 | 26 | System.out.bufferedWriter().use { 27 | it.write(size.toString()) 28 | it.write(sb.toString()) 29 | it.flush() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/boj_2033/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2033; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 2033번 (반올림) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/2033 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int N = Integer.parseInt(br.readLine()); 17 | br.close(); 18 | 19 | // 비교 변수 초기화 20 | int comp = 10; 21 | 22 | // 루프를 돌며 문제의 조건에 맞게 반올림 실행 23 | while (N > comp) { 24 | int nModComp = N % comp; 25 | 26 | if (nModComp * 10 / comp >= 5) { 27 | N += comp; 28 | } 29 | 30 | N -= nModComp; 31 | comp *= 10; 32 | } 33 | 34 | // 결과 값 출력 35 | System.out.println(N); 36 | } 37 | } -------------------------------------------------------------------------------- /src/boj_2869/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2869; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 2869번 (달팽이는 올라가고 싶다) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/2869 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String[] args) throws Exception { 15 | // 버퍼를 통해 입력을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | br.close(); 19 | 20 | int A = Integer.parseInt(st.nextToken()); 21 | int B = Integer.parseInt(st.nextToken()); 22 | int V = Integer.parseInt(st.nextToken()); 23 | 24 | // 올라가기 위한 날짜를 계산 25 | System.out.println((int) Math.ceil((double) (V - A) / (double) (A - B)) + 1); 26 | } 27 | } -------------------------------------------------------------------------------- /src/boj_1021/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1021 2 | 3 | import java.util.LinkedList 4 | import java.util.StringTokenizer 5 | 6 | fun main() { 7 | var st = StringTokenizer(readln()) 8 | 9 | val deque = LinkedList() 10 | repeat(st.nextToken().toInt()) { deque.offer(it + 1) } 11 | 12 | st = StringTokenizer(readln()) 13 | var shift = 0 14 | while (st.hasMoreTokens()) { 15 | val leftShift = deque.indexOf(st.nextToken().toInt()) 16 | val rightShift = deque.size - leftShift 17 | shift += if (leftShift < rightShift) { 18 | repeat(leftShift) { deque.offer(deque.poll()) } 19 | leftShift 20 | } else { 21 | repeat(rightShift) { deque.offerFirst(deque.pollLast()) } 22 | rightShift 23 | } 24 | deque.poll() 25 | } 26 | 27 | print(shift) 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_15990/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15990 2 | 3 | fun main() { 4 | val memory = Array(size = 100_001) { LongArray(size = 4) } 5 | memory[1][1] = 1 6 | memory[2][2] = 1 7 | memory[3][1] = 1 8 | memory[3][2] = 1 9 | memory[3][3] = 1 10 | 11 | for (i in 4..100_000) { 12 | memory[i][1] = (memory[i - 1][2] + memory[i - 1][3]) % 1_000_000_009L 13 | memory[i][2] = (memory[i - 2][1] + memory[i - 2][3]) % 1_000_000_009L 14 | memory[i][3] = (memory[i - 3][1] + memory[i - 3][2]) % 1_000_000_009L 15 | } 16 | 17 | System.out.bufferedWriter().use { bw -> 18 | repeat(readln().toInt()) { 19 | val n = readln().toInt() 20 | 21 | bw.write((memory[n].sum() % 1_000_000_009L).toString()) 22 | bw.write("\n") 23 | } 24 | 25 | bw.flush() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_2467/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2467 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.abs 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | 9 | val st = StringTokenizer(readln()) 10 | val a = IntArray(n) { st.nextToken().toInt() } 11 | 12 | var left = 0 13 | var right = a.lastIndex 14 | var b = Int.MAX_VALUE 15 | var matchedLeft = 0 16 | var matchedRight = right 17 | while (left < right) { 18 | val sum = a[left] + a[right] 19 | if (abs(sum) < abs(b)) { 20 | matchedLeft = left 21 | matchedRight = right 22 | b = sum 23 | } 24 | 25 | when { 26 | sum < 0 -> ++left 27 | 0 < sum -> --right 28 | else -> break 29 | } 30 | } 31 | 32 | print("${a[matchedLeft]} ${a[matchedRight]}") 33 | } 34 | -------------------------------------------------------------------------------- /src/boj_2501/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2501; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * 백준 온라인 저지 2501번 (약수 구하기) 문제풀이 7 | * 8 | * @see https://www.acmicpc.net/problem/2501 9 | * @author devetude 10 | */ 11 | public class Main { 12 | public static void main(String args[]) throws Exception { 13 | // 입력 값을 받음 14 | Scanner sc = new Scanner(System.in); 15 | int N = sc.nextInt(); 16 | int K = sc.nextInt(); 17 | sc.close(); 18 | 19 | // 몇번째 약수인지 확인하는 변수 20 | int index = 0; 21 | 22 | // 1부터 N까지 루프를 돌면서 약수인지 확인 23 | for (int i = 1; i <= N; i++) { 24 | if (N % i == 0) { 25 | index++; 26 | 27 | // 약수 일 경우 K번째인지 확인 28 | if (index == K) { 29 | // 결과 값 출력 30 | System.out.println(i); 31 | return; 32 | } 33 | } 34 | } 35 | 36 | // 결과 값 출력 (약수 갯수보다 입력된 K가 클 경우) 37 | System.out.println(0); 38 | } 39 | } -------------------------------------------------------------------------------- /src/boj_2587/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2587; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.Arrays; 6 | 7 | /** 8 | * 백준 온라인 저지 2587번 (대표값2) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/2587 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 이용해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | int[] nums = new int[5]; 18 | int sum = 0; 19 | 20 | for (int i = 0; i < 5; i++) { 21 | int num = Integer.parseInt(br.readLine()); 22 | sum += num; 23 | nums[i] = num; 24 | } 25 | 26 | br.close(); 27 | 28 | // 오름차순으로 정렬 29 | Arrays.sort(nums); 30 | 31 | // 평균 값과 중앙 값을 출력 32 | System.out.println(sum / 5); 33 | System.out.println(nums[2]); 34 | } 35 | } -------------------------------------------------------------------------------- /src/boj_16401/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_16401 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | var st = StringTokenizer(readln()) 8 | val m = st.nextToken().toInt() 9 | val n = st.nextToken().toInt() 10 | 11 | st = StringTokenizer(readln()) 12 | var maxLength = 1 13 | val lengths = IntArray(n) { st.nextToken().toInt().also { maxLength = max(maxLength, it) } } 14 | 15 | var low = 1 16 | var high = maxLength 17 | var result = 0 18 | while (low <= high) { 19 | val mid = low + high shr 1 20 | if (mid == 0) break 21 | 22 | val size = lengths.sumOf { it / mid } 23 | if (size < m) { 24 | high = mid - 1 25 | } else { 26 | result = mid 27 | low = mid + 1 28 | } 29 | } 30 | 31 | print(result) 32 | } 33 | -------------------------------------------------------------------------------- /src/boj_2805/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2805 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | var st = StringTokenizer(readln()) 8 | val n = st.nextToken().toInt() 9 | val m = st.nextToken().toInt() 10 | 11 | st = StringTokenizer(readln()) 12 | var maxHeight = 1L 13 | val heights = LongArray(n) { st.nextToken().toLong().also { maxHeight = max(maxHeight, it) } } 14 | 15 | var low = 1L 16 | var high = maxHeight 17 | var result = 0L 18 | while (low <= high) { 19 | val mid = low + high shr 1 20 | val size = heights.sumOf { (it - mid).coerceAtLeast(minimumValue = 0L) } 21 | if (size < m) { 22 | high = mid - 1L 23 | } else { 24 | result = mid 25 | low = mid + 1L 26 | } 27 | } 28 | 29 | print(result) 30 | } 31 | -------------------------------------------------------------------------------- /src/boj_1003/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1003 2 | 3 | fun main() { 4 | System.out.bufferedWriter().use { bw -> 5 | repeat(readln().toInt()) { 6 | val n = readln().toInt() 7 | 8 | val counts = Array(size = 41) { Count(zero = 0, one = 0) } 9 | counts[0] = Count(zero = 1, one = 0) 10 | counts[1] = Count(zero = 0, one = 1) 11 | 12 | for (i in 2..n) { 13 | counts[i] = counts[i - 2] + counts[i - 1] 14 | } 15 | 16 | bw.write(counts[n].toString()) 17 | bw.write("\n") 18 | } 19 | 20 | bw.flush() 21 | } 22 | } 23 | 24 | data class Count(val zero: Int, val one: Int) { 25 | operator fun plus(other: Count): Count = Count(zero = zero + other.zero, one = one + other.one) 26 | 27 | override fun toString(): String = "$zero $one" 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_1644/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1644 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | if (n < 2) return print(0) 6 | 7 | val isPrime = BooleanArray(size = n + 1) { true } 8 | isPrime[0] = false 9 | isPrime[1] = false 10 | for (num in 2..n) { 11 | if (!isPrime[num]) continue 12 | 13 | for (multiple in (num shl 1)..n step num) { 14 | isPrime[multiple] = false 15 | } 16 | } 17 | 18 | var left = 2 19 | var right = 2 20 | var sum = 0 21 | var count = 0 22 | while (left <= n) { 23 | while (sum < n && right <= n) { 24 | if (isPrime[right]) sum += right 25 | ++right 26 | } 27 | 28 | if (sum == n) ++count 29 | 30 | sum -= left++ 31 | while (left <= n && !isPrime[left]) ++left 32 | } 33 | 34 | print(count) 35 | } 36 | -------------------------------------------------------------------------------- /src/boj_10156/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10156; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 10156번 (과자) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/10156 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String[] args) throws Exception { 15 | // 버퍼를 이용해 입력을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | br.close(); 19 | 20 | int K = Integer.parseInt(st.nextToken()); 21 | int N = Integer.parseInt(st.nextToken()); 22 | int M = Integer.parseInt(st.nextToken()); 23 | 24 | // 부족한 금액 계산 25 | int lackMoney = K * N - M; 26 | 27 | // 결과 값 출력 28 | System.out.println(lackMoney > 0 ? lackMoney : 0); 29 | } 30 | } -------------------------------------------------------------------------------- /src/boj_22857/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_22857 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | var st = StringTokenizer(readln()) 8 | val n = st.nextToken().toInt() 9 | val k = st.nextToken().toInt() 10 | 11 | st = StringTokenizer(readln()) 12 | val nums = IntArray(n) 13 | repeat(n) { nums[it] = st.nextToken().toInt() } 14 | 15 | var start = 0 16 | var oddCount = 0 17 | var maxLength = 0 18 | for (end in 0 until n) { 19 | if (nums[end] and 1 == 1) { 20 | if (oddCount < k) { 21 | ++oddCount 22 | } else { 23 | while (nums[start] and 1 == 0) ++start 24 | ++start 25 | } 26 | } 27 | maxLength = max(maxLength, b = end - start + 1 - oddCount) 28 | } 29 | 30 | print(maxLength) 31 | } 32 | -------------------------------------------------------------------------------- /src/boj_11328/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11328 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | System.out.bufferedWriter().use { bw -> 7 | repeat(readln().toInt()) { 8 | val st = StringTokenizer(readln()) 9 | val a = st.nextToken() 10 | val b = st.nextToken() 11 | if (a.length != b.length) { 12 | bw.write("Impossible") 13 | return@repeat bw.write("\n") 14 | } 15 | 16 | val counts = IntArray(size = 26) 17 | for (i in a.indices) { 18 | ++counts[a[i] - 'a'] 19 | --counts[b[i] - 'a'] 20 | } 21 | 22 | val result = if (counts.any { it != 0 }) "Impossible" else "Possible" 23 | bw.write(result) 24 | bw.write("\n") 25 | } 26 | bw.flush() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/boj_2935/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2935; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * 백준 온라인 저지 2935번 (소음) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/2935 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | BigDecimal A = new BigDecimal(br.readLine()); 18 | String operator = br.readLine(); 19 | BigDecimal B = new BigDecimal(br.readLine()); 20 | br.close(); 21 | 22 | // 연산자가 +일 경우 23 | if (operator.equals("+")) { 24 | // 결과 값 출력 25 | System.out.println(A.add(B)); 26 | } 27 | 28 | // 연산자가 *일 경우 29 | else { 30 | // 결과 값 출력 31 | System.out.println(A.multiply(B)); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/boj_5639/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_5639 2 | 3 | val sb = StringBuilder() 4 | 5 | fun main() { 6 | val root = Node(readln().toInt()) 7 | while (true) readlnOrNull()?.toInt()?.let(root::add) ?: break 8 | postorder(root) 9 | 10 | System.out.bufferedWriter().use { 11 | it.write(sb.toString()) 12 | it.flush() 13 | } 14 | } 15 | 16 | fun postorder(node: Node) { 17 | node.left?.let(::postorder) 18 | node.right?.let(::postorder) 19 | sb.appendLine(node.value) 20 | } 21 | 22 | data class Node( 23 | val value: Int, 24 | var left: Node? = null, 25 | var right: Node? = null 26 | ) { 27 | fun add(value: Int) { 28 | if (value < this.value) { 29 | left?.add(value) ?: run { left = Node(value) } 30 | } else { 31 | right?.add(value) ?: run { right = Node(value) } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/boj_9546/Main.java: -------------------------------------------------------------------------------- 1 | package boj_9546; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 9546번 (3000번 버스) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/9546 10 | * @author devetude 11 | */ 12 | public class Main { 13 | // 개행 문자열 상수 14 | private static final String NEW_LINE = "\n"; 15 | 16 | public static void main(String args[]) throws Exception { 17 | // 버퍼를 통해 입력 값을 받음 18 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 19 | int T = Integer.parseInt(br.readLine()); 20 | 21 | // 버퍼를 통해 결과 값을 만듬 22 | StringBuilder sb = new StringBuilder(); 23 | 24 | while (T-- != 0) { 25 | sb.append((int) Math.pow(2, Integer.parseInt(br.readLine())) - 1).append(NEW_LINE); 26 | } 27 | 28 | br.close(); 29 | 30 | // 결과 값 한꺼번에 출력 31 | System.out.println(sb.toString()); 32 | } 33 | } -------------------------------------------------------------------------------- /src/boj_11094/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11094; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 11094번 (꿍 가라사대) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/11094 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int N = Integer.parseInt(br.readLine()); 17 | StringBuilder sb = new StringBuilder(); 18 | 19 | for (int i = 0; i < N; i++) { 20 | String say = br.readLine(); 21 | 22 | // 'Simon says '로 시작하면 결과 값을 버퍼에 저장 23 | if (say.startsWith("Simon says ")) { 24 | sb.append(say.substring(10)).append("\n"); 25 | } 26 | } 27 | 28 | br.close(); 29 | 30 | // 결과 값 한꺼번에 출력 31 | System.out.println(sb.toString()); 32 | } 33 | } -------------------------------------------------------------------------------- /src/boj_1747/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1747 2 | 3 | import kotlin.math.sqrt 4 | 5 | fun main() { 6 | val n = readln().toInt() 7 | 8 | val isPrime = BooleanArray(size = 1_003_002) { true }.apply { 9 | this[0] = false 10 | this[1] = false 11 | } 12 | 13 | for (num in 2..sqrt(isPrime.lastIndex.toDouble()).toInt()) { 14 | if (!isPrime[num]) continue 15 | for (j in num * num until isPrime.size step num) isPrime[j] = false 16 | } 17 | 18 | for (num in n until isPrime.size) { 19 | if (isPrime[num] && isPalindrome(num)) return print(num) 20 | } 21 | 22 | print(2) 23 | } 24 | 25 | private fun isPalindrome(num: Int): Boolean { 26 | val str = num.toString() 27 | var left = 0 28 | var right = str.lastIndex 29 | while (left < right) if (str[left++] != str[right--]) return false 30 | 31 | return true 32 | } 33 | -------------------------------------------------------------------------------- /src/boj_10039/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10039; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 10039번 (평균 점수) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/10039 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | 17 | // 점수의 합 저장 변수 18 | int sum = 0; 19 | 20 | for (int i = 0; i < 5; i++) { 21 | int score = Integer.parseInt(br.readLine()); 22 | 23 | // 점수가 40점 미만인 경우 40점을 점수의 합에 더함 24 | if (score < 40) { 25 | sum += 40; 26 | } 27 | 28 | // 점수가 40점 이상일 경우 입력된 점수를 점수의 합에 더함 29 | else { 30 | sum += score; 31 | } 32 | } 33 | 34 | br.close(); 35 | 36 | // 결과 값 출력 37 | System.out.println(sum / 5); 38 | } 39 | } -------------------------------------------------------------------------------- /src/boj_10797/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10797; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 10797번 (10부제) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/10797 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String[] args) throws Exception { 15 | // 버퍼를 이용해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | String day = br.readLine(); 18 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 19 | br.close(); 20 | 21 | int violateCounts = 0; 22 | 23 | // 위반 차량의 숫자를 셈 24 | for (int i = 0; i < 5; i++) { 25 | if (day.equals(st.nextToken())) { 26 | violateCounts++; 27 | } 28 | } 29 | 30 | br.close(); 31 | 32 | // 결과 값 출력 33 | System.out.println(violateCounts); 34 | } 35 | } -------------------------------------------------------------------------------- /src/boj_14430/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_14430 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | var st = StringTokenizer(readln()) 8 | val n = st.nextToken().toInt() 9 | val m = st.nextToken().toInt() 10 | val hasOre = Array(size = n + 1) { BooleanArray(size = m + 1) } 11 | repeat(n) { i -> 12 | st = StringTokenizer(readln()) 13 | repeat(m) { j -> 14 | hasOre[i + 1][j + 1] = st.nextToken() == "1" 15 | } 16 | } 17 | 18 | val maxValues = Array(size = n + 1) { IntArray(size = m + 1) } 19 | for (row in 1..n) { 20 | for (col in 1..m) { 21 | val previousMaxValue = max(maxValues[row - 1][col], maxValues[row][col - 1]) 22 | maxValues[row][col] = previousMaxValue + if (hasOre[row][col]) 1 else 0 23 | } 24 | } 25 | 26 | print(maxValues[n][m]) 27 | } 28 | -------------------------------------------------------------------------------- /src/boj_1535/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1535 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.max 5 | 6 | fun main() { 7 | val n = readln().toInt() 8 | 9 | var st = StringTokenizer(readln()) 10 | val healths = IntArray(size = n + 1) 11 | repeat(n) { healths[it + 1] = st.nextToken().toInt() } 12 | 13 | st = StringTokenizer(readln()) 14 | val joys = IntArray(size = n + 1) 15 | repeat(n) { joys[it + 1] = st.nextToken().toInt() } 16 | 17 | val maxJoys = Array(size = n + 1) { IntArray(size = 101) } 18 | for (i in 1..n) { 19 | for (j in 1..100) { 20 | maxJoys[i][j] = if (healths[i] <= j) { 21 | max(a = joys[i] + maxJoys[i - 1][j - healths[i]], maxJoys[i - 1][j]) 22 | } else { 23 | maxJoys[i - 1][j] 24 | } 25 | } 26 | } 27 | 28 | print(maxJoys[n][99]) 29 | } 30 | -------------------------------------------------------------------------------- /src/boj_20920/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_20920 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val m = st.nextToken().toInt() 9 | 10 | val words = HashMap() 11 | repeat(n) { 12 | val word = readln() 13 | if (word.length < m) return@repeat 14 | 15 | val count = words.getOrDefault(word, defaultValue = 0) 16 | words[word] = count + 1 17 | } 18 | 19 | val result = words 20 | .toSortedMap( 21 | compareByDescending { words[it] } 22 | .thenByDescending { it.length } 23 | .thenBy { it } 24 | ) 25 | .keys 26 | .joinToString(separator = "\n") 27 | 28 | System.out.bufferedWriter().use { 29 | it.write(result) 30 | it.flush() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/boj_7567/Main.java: -------------------------------------------------------------------------------- 1 | package boj_7567; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 7567번 (그릇) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/7567 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String[] args) throws Exception { 14 | // 입력 값을 버퍼를 이용해 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | String bowls = br.readLine(); 17 | br.close(); 18 | 19 | int totalHeight = 10; 20 | int bowlsLen = bowls.length(); 21 | 22 | // 이전 그릇 모양과 같으면 5를 더하고 다르면 10을 더함 23 | for (int i = 1; i < bowlsLen; i++) { 24 | if (bowls.charAt(i) == bowls.charAt(i - 1)) { 25 | totalHeight += 5; 26 | } 27 | 28 | else { 29 | totalHeight += 10; 30 | } 31 | } 32 | 33 | // 결과 값 출력 34 | System.out.println(totalHeight); 35 | } 36 | } -------------------------------------------------------------------------------- /src/boj_2294/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2294 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val k = st.nextToken().toInt() 9 | 10 | val coins = HashSet() 11 | val maxCounts = IntArray(size = k + 1) 12 | repeat(n) { 13 | val coin = readln().toInt() 14 | if (coin <= k) { 15 | maxCounts[coin] = 1 16 | coins.add(coin) 17 | } 18 | } 19 | 20 | for (sum in 1..k) { 21 | if (maxCounts[sum] == 1) continue 22 | 23 | maxCounts[sum] = coins.asSequence() 24 | .filter { it <= sum && maxCounts[sum - it] < 10_001 } 25 | .minOfOrNull { maxCounts[sum - it] + 1 } 26 | ?: 10_001 27 | } 28 | 29 | val result = if (maxCounts[k] == 10_001) -1 else maxCounts[k] 30 | print(result) 31 | } 32 | -------------------------------------------------------------------------------- /src/boj_2986/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2986; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 2986번 (파스칼) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/2986 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int N = Integer.parseInt(br.readLine()); 17 | br.close(); 18 | 19 | // N의 제곱근 저장 변수 20 | int sqrtN = (int) Math.sqrt(N); 21 | 22 | // 가장 큰 약수 저장 변수 23 | int max = 1; 24 | 25 | // 루프를 돌며 N 보다 작은 N의 가장 큰 약수를 찾음 26 | for (int i = sqrtN; 2 <= i; i--) { 27 | if (N % i == 0) { 28 | max = Math.max(i, N / i); 29 | } 30 | } 31 | 32 | // 결과 값 출력 33 | // (문제의 조건에서 counter = N - max) 34 | System.out.println(N - max); 35 | } 36 | } -------------------------------------------------------------------------------- /src/boj_11497/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11497 2 | 3 | import java.util.StringTokenizer 4 | import kotlin.math.abs 5 | import kotlin.math.max 6 | 7 | fun main() { 8 | val t = readln().toInt() 9 | val result = buildString { 10 | repeat(t) { 11 | val n = readln().toInt() 12 | val st = StringTokenizer(readln()) 13 | val heights = IntArray(n) 14 | repeat(n) { heights[it] = st.nextToken().toInt() } 15 | 16 | heights.sort() 17 | var maxDiff = heights[1] - heights.first() 18 | for (i in 2 until n) { 19 | val diff = abs(n = heights[i] - heights[i - 2]) 20 | maxDiff = max(maxDiff, diff) 21 | } 22 | appendLine(maxDiff) 23 | } 24 | } 25 | 26 | System.out.bufferedWriter().use { 27 | it.write(result) 28 | it.flush() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/boj_10707/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10707; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 10707번 (수도요금) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/10707 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int A = Integer.parseInt(br.readLine()); 17 | int B = Integer.parseInt(br.readLine()); 18 | int C = Integer.parseInt(br.readLine()); 19 | int D = Integer.parseInt(br.readLine()); 20 | int P = Integer.parseInt(br.readLine()); 21 | 22 | br.close(); 23 | 24 | // 수도요금을 계산 25 | int x = A * P; 26 | int y = B; 27 | 28 | if (P > C) { 29 | y += (P - C) * D; 30 | } 31 | 32 | // 결과 값 출력 33 | System.out.println(Math.min(x, y)); 34 | } 35 | } -------------------------------------------------------------------------------- /src/boj_1100/Main.java: -------------------------------------------------------------------------------- 1 | package boj_1100; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 1100번 (하얀 칸) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/1100 10 | * @author devetude 11 | */ 12 | public class Main { 13 | // 문자 상수 14 | private static final char IS_FILLED = 'F'; 15 | 16 | public static void main(String args[]) throws Exception { 17 | // 버퍼를 통해 입력 값을 받음 18 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 19 | 20 | // 결과 값 저장 변수 21 | int res = 0; 22 | 23 | // 루프를 돌며 체스판의 흰색 영역에 있는 말의 갯수를 셈 24 | for (int i = 0; i < 8; i++) { 25 | String line = br.readLine(); 26 | 27 | for (int j = i % 2; j < 8; j += 2) { 28 | if (line.charAt(j) == IS_FILLED) { 29 | res++; 30 | } 31 | } 32 | } 33 | 34 | br.close(); 35 | 36 | // 결과 값 출력 37 | System.out.println(res); 38 | } 39 | } -------------------------------------------------------------------------------- /src/boj_11047/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_11047 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | val st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | var k = st.nextToken().toInt() 9 | 10 | val coins = IntArray(n) { readln().toInt() } 11 | 12 | var size = 0 13 | while (0 < k) { 14 | val i = coins.lowerBound(k).coerceAtMost(coins.lastIndex) 15 | val coin = if (k < coins[i]) coins[i - 1] else coins[i] 16 | with(k / coin) { 17 | size += this 18 | k -= this * coin 19 | } 20 | } 21 | 22 | print(size) 23 | } 24 | 25 | private fun IntArray.lowerBound(value: Int): Int { 26 | var low = 0 27 | var high = size 28 | while (low < high) { 29 | val mid = low + high shr 1 30 | if (this[mid] < value) low = mid + 1 else high = mid 31 | } 32 | 33 | return high 34 | } 35 | -------------------------------------------------------------------------------- /src/boj_16916/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_16916 2 | 3 | fun main() { 4 | val s = readln() 5 | val p = readln() 6 | 7 | val pi = pi(p) 8 | val result = if (-1 < kmp(s, p, pi)) 1 else 0 9 | 10 | print(result) 11 | } 12 | 13 | fun pi(pattern: String): IntArray { 14 | val pi = IntArray(pattern.length) 15 | 16 | var j = 0 17 | for (i in 1 until pattern.length) { 18 | while (0 < j && pattern[i] != pattern[j]) j = pi[j - 1] 19 | if (pattern[i] == pattern[j]) pi[i] = ++j 20 | } 21 | 22 | return pi 23 | } 24 | 25 | fun kmp(str: String, pattern: String, pi: IntArray): Int { 26 | var j = 0 27 | for (i in str.indices) { 28 | while (0 < j && str[i] != pattern[j]) j = pi[j - 1] 29 | if (str[i] == pattern[j]) { 30 | if (j == pattern.lastIndex) return pi[j] 31 | ++j 32 | } 33 | } 34 | 35 | return -1 36 | } 37 | -------------------------------------------------------------------------------- /src/boj_2965/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2965; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 2965번 (캥거루 세마리) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/2965 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | int[] pos = new int[3]; 19 | 20 | for (int i = 0; i < 3; i++) { 21 | pos[i] = Integer.parseInt(st.nextToken()); 22 | } 23 | 24 | br.close(); 25 | 26 | // 최대 움직일 수 있는 거리 = 0번, 1번 간격과 1번, 2번 간격 중 큰 쪽 - 1 27 | int maxCnt = Math.max(pos[1] - pos[0], pos[2] - pos[1]) - 1; 28 | 29 | // 결과 값 출력 30 | System.out.println(maxCnt); 31 | } 32 | } -------------------------------------------------------------------------------- /src/boj_4150/Main.java: -------------------------------------------------------------------------------- 1 | package boj_4150; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * 백준 온라인 저지 4150번 (피보나치 수) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/4150 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | int N = Integer.parseInt(br.readLine()); 18 | 19 | br.close(); 20 | 21 | // 피보나치 배열 초기화 22 | BigDecimal[] fibo = new BigDecimal[N + 1]; 23 | 24 | // 피보나치 수열의 첫번째와 두번째 값을 1로 설정 25 | fibo[1] = fibo[2] = BigDecimal.ONE; 26 | 27 | // N까지 피보나치 수열을 구함 28 | for (int i = 3; i <= N; i++) { 29 | fibo[i] = fibo[i - 2].add(fibo[i - 1]); 30 | } 31 | 32 | // 결과 값 출력 33 | System.out.println(fibo[N]); 34 | } 35 | } -------------------------------------------------------------------------------- /src/boj_11721/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11721; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 11721번 (열 개씩 끊어 출력하기) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/11721 10 | * @author devetude 11 | */ 12 | public class Main { 13 | private static final String NEW_LINE = "\n"; 14 | 15 | public static void main(String args[]) throws Exception { 16 | // 버퍼를 통해 입력 값을 받음 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | char[] wordChars = br.readLine().toCharArray(); 19 | br.close(); 20 | 21 | StringBuilder sb = new StringBuilder(); 22 | 23 | for (int i = 0; i < wordChars.length; i++) { 24 | // 10개의 단어가 차면 줄바꿈 25 | if (i != 0 && i % 10 == 0) { 26 | sb.append(NEW_LINE); 27 | } 28 | 29 | sb.append(wordChars[i]); 30 | } 31 | 32 | // 결과 값 출력 33 | System.out.println(sb.toString()); 34 | } 35 | } -------------------------------------------------------------------------------- /src/boj_1789/Main.java: -------------------------------------------------------------------------------- 1 | package boj_1789; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 1789번 (수들의 합) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/1789 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 버퍼를 통해 입력 값을 받음 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | 17 | // 문제의 조건에서 약 43억 이하가 입력 됨으로 long형 사용 18 | long N = Long.parseLong(br.readLine()); 19 | 20 | br.close(); 21 | 22 | int i = 1; 23 | 24 | // 합계 저장 변수는 최대 43억 이하가 저장 됨으로 long형 사용 25 | long sum = 0; 26 | 27 | // 규칙성을 통해 i 값을 찾음 28 | // 합계 : 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... 29 | // 갯수 : 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, ... 30 | for (; sum + i <= N; i++) { 31 | sum += i; 32 | } 33 | 34 | // 결과 값 출력 35 | System.out.println(i - 1); 36 | } 37 | } -------------------------------------------------------------------------------- /src/boj_2355/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2355; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 2355번 (시그마) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/2355 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | long i = Long.parseLong(st.nextToken()); 19 | long j = Long.parseLong(st.nextToken()); 20 | br.close(); 21 | 22 | // 앞에서 입력받은 숫자가 더 큰 경우 앞뒤 숫자를 변경 23 | if (i > j) { 24 | long tmp = i; 25 | i = j; 26 | j = tmp; 27 | } 28 | 29 | // 결과 값 출력 30 | // 등차수열의 합 공식 : n * (a + l) / 2 31 | System.out.println((j - i + 1L) * (i + j) / 2L); 32 | } 33 | } -------------------------------------------------------------------------------- /src/boj_2668/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_2668 2 | 3 | fun main() { 4 | val n = readln().toInt() 5 | val nexts = MutableList(size = n + 1) { 0 } 6 | repeat(n) { 7 | nexts[it + 1] = readln().toInt() 8 | } 9 | 10 | val elements = mutableSetOf() 11 | for (start in 1..n) { 12 | if (start in elements) continue 13 | 14 | val visits = mutableSetOf() 15 | visits.add(start) 16 | 17 | var next = nexts[start] 18 | while (next !in visits) { 19 | visits.add(next) 20 | next = nexts[next] 21 | } 22 | 23 | if (start == next) elements.addAll(visits) 24 | } 25 | val result = buildString { 26 | appendLine(elements.size) 27 | elements.sorted().forEach { appendLine(it) } 28 | } 29 | 30 | System.out.bufferedWriter().use { 31 | it.write(result) 32 | it.flush() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/boj_10807/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10807; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 10807번 (개수 세기) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/10807 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | int N = Integer.parseInt(br.readLine()); 18 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 19 | int v = Integer.parseInt(br.readLine()); 20 | 21 | br.close(); 22 | 23 | // 갯수 저장 변수 초기화 24 | int cnt = 0; 25 | 26 | // v의 갯수를 셈 27 | while (N-- != 0) { 28 | if (Integer.parseInt(st.nextToken()) == v) { 29 | cnt++; 30 | } 31 | } 32 | 33 | // 결과 값 출력 34 | System.out.println(cnt); 35 | } 36 | } -------------------------------------------------------------------------------- /src/boj_15988/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_15988 2 | 3 | fun main() { 4 | System.out.bufferedWriter().use { bw -> 5 | repeat(readln().toInt()) { 6 | val n = readln().toInt() 7 | 8 | val memory = LongArray(size = 4) 9 | memory[0] = 1 10 | memory[1] = 2 11 | memory[2] = 4 12 | if (n < 4) { 13 | bw.write(memory[n - 1].toString()) 14 | bw.write("\n") 15 | return@repeat 16 | } 17 | 18 | for (i in 4..n) { 19 | memory[3] = (memory[0] + memory[1] + memory[2]) % 1_000_000_009 20 | memory[0] = memory[1] 21 | memory[1] = memory[2] 22 | memory[2] = memory[3] 23 | } 24 | 25 | bw.write(memory[3].toString()) 26 | bw.write("\n") 27 | } 28 | 29 | bw.flush() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/boj_10951/Main.java: -------------------------------------------------------------------------------- 1 | package boj_10951; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 10951번 (A+B - 4) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/10951 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 이용해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | 18 | // 버퍼를 이용해 결과 값을 저장 19 | StringBuilder sb = new StringBuilder(); 20 | 21 | String line = null; 22 | 23 | while ((line = br.readLine()) != null) { 24 | StringTokenizer st = new StringTokenizer(line, " "); 25 | sb.append(Integer.parseInt(st.nextToken()) + Integer.parseInt(st.nextToken())).append("\n"); 26 | } 27 | 28 | br.close(); 29 | 30 | // 결과 값 한꺼번에 출력 31 | System.out.println(sb.toString()); 32 | } 33 | } -------------------------------------------------------------------------------- /src/boj_11726/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11726; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 11726번 (2×n 타일링) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/11726 10 | * @author devetude 11 | */ 12 | public class Main { 13 | private static int[] cache = null; 14 | 15 | public static void main(String args[]) throws Exception { 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | int n = Integer.parseInt(br.readLine()); 18 | br.close(); 19 | 20 | cache = new int[n + 1]; 21 | 22 | System.out.println(fill(n)); 23 | } 24 | 25 | private static int fill(int n) { 26 | if (n == 1) { 27 | return 1; 28 | } 29 | 30 | if (n == 2) { 31 | return 2; 32 | } 33 | 34 | if (cache[n] != 0) { 35 | return cache[n]; 36 | } 37 | 38 | return cache[n] = (fill(n - 1) % 10007 + fill(n - 2) % 10007) % 10007; 39 | } 40 | } -------------------------------------------------------------------------------- /src/boj_1712/Main.java: -------------------------------------------------------------------------------- 1 | package boj_1712; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.util.StringTokenizer; 6 | 7 | /** 8 | * 백준 온라인 저지 1712번 (손익분기점) 문제풀이 9 | * 10 | * @see https://www.acmicpc.net/problem/1712 11 | * @author devetude 12 | */ 13 | public class Main { 14 | public static void main(String args[]) throws Exception { 15 | // 버퍼를 통해 입력 값을 받음 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | StringTokenizer st = new StringTokenizer(br.readLine(), " "); 18 | 19 | br.close(); 20 | 21 | int A = Integer.parseInt(st.nextToken()); 22 | int B = Integer.parseInt(st.nextToken()); 23 | int C = Integer.parseInt(st.nextToken()); 24 | 25 | // 손익분기점이 생길 수 없는 예외일 경우 26 | if (B >= C) { 27 | System.out.println(-1); 28 | } 29 | 30 | else { 31 | // 결과 값 출력 32 | System.out.println(A / (C - B) + 1); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/boj_11653/Main.java: -------------------------------------------------------------------------------- 1 | package boj_11653; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | 6 | /** 7 | * 백준 온라인 저지 11653번 (소인수분해) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/11653 10 | * @author devetude 11 | */ 12 | public class Main { 13 | // 개행 문자열 상수 14 | private static final String NEW_LINE = "\n"; 15 | 16 | public static void main(String args[]) throws Exception { 17 | // 버퍼를 통해 입력 값을 받음 18 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 19 | int N = Integer.parseInt(br.readLine()); 20 | br.close(); 21 | 22 | // 버퍼를 통해 결과 값을 만듬 23 | StringBuilder sb = new StringBuilder(); 24 | int i = 2; 25 | 26 | while (N != 1) { 27 | if (N % i == 0) { 28 | sb.append(i).append(NEW_LINE); 29 | N /= i; 30 | } 31 | 32 | else { 33 | i++; 34 | } 35 | } 36 | 37 | // 결과 값 출력 38 | System.out.println(sb.toString()); 39 | } 40 | } -------------------------------------------------------------------------------- /src/boj_1806/Kotlin.kt: -------------------------------------------------------------------------------- 1 | package boj_1806 2 | 3 | import java.util.StringTokenizer 4 | 5 | fun main() { 6 | var st = StringTokenizer(readln()) 7 | val n = st.nextToken().toInt() 8 | val s = st.nextToken().toLong() 9 | 10 | st = StringTokenizer(readln()) 11 | var acc = 0L 12 | val subSums = LongArray(n) { acc += st.nextToken().toLong(); acc } 13 | 14 | var left = 0 15 | var right = 0 16 | var minLen = Int.MAX_VALUE 17 | while (left < n && right < n) { 18 | val sum = subSums[right] - if (0 < left) subSums[left - 1] else 0L 19 | if (sum < s) { 20 | ++right 21 | } else { 22 | val len = right - left + 1 23 | if (len < minLen) minLen = len 24 | 25 | ++left 26 | if (right < left) right = left 27 | } 28 | } 29 | 30 | val result = if (minLen == Int.MAX_VALUE) 0 else minLen 31 | print(result) 32 | } 33 | -------------------------------------------------------------------------------- /src/boj_2526/Main.java: -------------------------------------------------------------------------------- 1 | package boj_2526; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Scanner; 5 | 6 | /** 7 | * 백준 온라인 저지 2526번 (싸이클) 문제풀이 8 | * 9 | * @see https://www.acmicpc.net/problem/2526 10 | * @author devetude 11 | */ 12 | public class Main { 13 | public static void main(String args[]) throws Exception { 14 | // 입력 값을 받음 15 | Scanner sc = new Scanner(System.in); 16 | ArrayList cycle = new ArrayList<>(); 17 | int N = sc.nextInt(); 18 | int P = sc.nextInt(); 19 | sc.close(); 20 | int item = N; 21 | int cycleStartIndex = 0; 22 | 23 | // 싸이클이 나올 때 까지 반복 24 | while (true) { 25 | item = item * N % P; 26 | 27 | if (cycle.contains(item)) { 28 | cycleStartIndex = cycle.indexOf(item); 29 | break; 30 | } 31 | 32 | else { 33 | cycle.add(item); 34 | } 35 | } 36 | 37 | // 싸이클의 크기를 결과 값으로 출력 38 | System.out.println(cycle.size() - cycleStartIndex); 39 | } 40 | } --------------------------------------------------------------------------------