diff --git "a/src/main/kotlin/hyunsoo/12week/\352\267\270\353\243\271 \353\213\250\354\226\264 \354\262\264\354\273\244.kt" "b/src/main/kotlin/hyunsoo/12week/\352\267\270\353\243\271 \353\213\250\354\226\264 \354\262\264\354\273\244.kt" new file mode 100644 index 00000000..a8c11404 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/12week/\352\267\270\353\243\271 \353\213\250\354\226\264 \354\262\264\354\273\244.kt" @@ -0,0 +1,38 @@ +package hyunsoo.`12week` + + +/** + * <문제> + * [그룹 단어 체커](https://www.acmicpc.net/problem/1316) + * + * 문자열을 순차탐색하며 등장한 문자들을 list에 담는다. + * 이전의 단어와 현재의 단어가 다를 때 바뀐단어가 기존에 등장했다면 그룹단어가 아님!! + */ +fun main() { + + val wordCnt = readln().toInt() + var groupWordCnt = 0 + + repeat(wordCnt) { + + val existedWordList = mutableListOf() + val targetWord = readln() + var lastChar = targetWord.first().apply { + existedWordList.add(this) + } + + targetWord.drop(1).forEach { curChar -> + if (lastChar != curChar) { + if (curChar in existedWordList) { + return@repeat + } else { + existedWordList.add(curChar) + lastChar = curChar + } + } + } + groupWordCnt++ + } + + println(groupWordCnt) +} diff --git "a/src/main/kotlin/hyunsoo/12week/\354\210\230\353\246\254\352\263\265 \355\225\255\354\212\271.kt" "b/src/main/kotlin/hyunsoo/12week/\354\210\230\353\246\254\352\263\265 \355\225\255\354\212\271.kt" new file mode 100644 index 00000000..5f518e78 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/12week/\354\210\230\353\246\254\352\263\265 \355\225\255\354\212\271.kt" @@ -0,0 +1,27 @@ +package hyunsoo.`12week` + +/** + * <문제> + * [수리공 항승](https://www.acmicpc.net/problem/1449) + * + * 물새는 곳을 하나씩 막아보자앗..!! + */ +fun main() { + + val (_, tapeLength) = readln().split(" ").map { it.toInt() } + val leakPositionList = readln().split(" ") + .map { it.toInt() } + .sorted() + + var lastTapedPosition = leakPositionList.first() + tapeLength - 0.5f + var tapedCnt = 1 + + leakPositionList.drop(1).forEach { leakPosition -> + if (lastTapedPosition < leakPosition) { + lastTapedPosition = leakPosition + tapeLength - 0.5f + tapedCnt++ + } + } + + println(tapedCnt) +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/12week/\355\212\270\353\237\255.kt" "b/src/main/kotlin/hyunsoo/12week/\355\212\270\353\237\255.kt" new file mode 100644 index 00000000..bb5e94d9 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/12week/\355\212\270\353\237\255.kt" @@ -0,0 +1,61 @@ +package hyunsoo.`12week` + +import java.util.ArrayDeque +import java.util.Queue + +/** + * <문제> + * [트럭](https://www.acmicpc.net/problem/13335) + * + * + */ + +data class Truck(var weight: Int, var pos: Int = 1) { + fun move() { + this.pos++ + } +} + +fun main() { + + val waitQueue: Queue = ArrayDeque() + val processQueue: Queue = ArrayDeque() + var usedTime = 1 + + val (_, bridgeLength, bridgeMaxWeight) = readln().split(" ").map { it.toInt() } + + readln().split(" ") + .map { it.toInt() } + .forEach { weight -> + waitQueue.add(Truck(weight)) + } + + var isArrived = false + while (waitQueue.isNotEmpty() || processQueue.isNotEmpty()) { + + usedTime++ + + // 최대 하중 무게만큼 트럭 올리기 + if (waitQueue.isNotEmpty() && + processQueue.sumOf { it.weight } + waitQueue.peek().weight <= bridgeMaxWeight + ) { + processQueue.add(waitQueue.poll()) + } + + // 트럭들 이동 + processQueue.forEach { truck -> + truck.apply { + move() + if (bridgeLength < this.pos) isArrived = true + } + } + + if (isArrived) { + processQueue.poll() + isArrived = false + } + } + + println(usedTime) + +} \ No newline at end of file