Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[전현수] 그룹 단어 체커, 수리공 항승, 트럭 #59

Merged
merged 3 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/main/kotlin/hyunsoo/12week/그룹 단어 체커.kt
Original file line number Diff line number Diff line change
@@ -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<Char>()
val targetWord = readln()
var lastChar = targetWord.first().apply {
existedWordList.add(this)
}

targetWord.drop(1).forEach { curChar ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

첫번째 단어를 앞에서 미리 처리해주고 drop처리 해주신 부분 좋네요!

if (lastChar != curChar) {
if (curChar in existedWordList) {
return@repeat
} else {
existedWordList.add(curChar)
lastChar = curChar
}
}
}
groupWordCnt++
}

println(groupWordCnt)
}
27 changes: 27 additions & 0 deletions src/main/kotlin/hyunsoo/12week/수리공 항승.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hyunsoo.`12week`

/**
* <문제>
* [수리공 항승](https://www.acmicpc.net/problem/1449)
*
* 물새는 곳을 하나씩 막아보자앗..!!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가즈앗..!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeeminimini
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

*/
fun main() {

val (_, tapeLength) = readln().split(" ").map { it.toInt() }
val leakPositionList = readln().split(" ")
.map { it.toInt() }
.sorted()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

입력받으면서 바로 sort한게 좋네요!


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)
}
61 changes: 61 additions & 0 deletions src/main/kotlin/hyunsoo/12week/트럭.kt
Original file line number Diff line number Diff line change
@@ -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++
}
Comment on lines +14 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data class의 함수로 만든게 깔끔하고 좋았어요 !

}

fun main() {

val waitQueue: Queue<Truck> = ArrayDeque()
val processQueue: Queue<Truck> = ArrayDeque()
Comment on lines +21 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정말 스케줄링 하는 것처럼 구현하셔서 챌린지가 떠올랐습니다

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhg3410
나중에 그거 같이해봐야죠?...ㅎㅎ

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

하나씩 이동하니 Boolean 으로 처리해도 되네요!👍 전 filter 를 썼는데

while (waitQueue.isNotEmpty() || processQueue.isNotEmpty()) {

usedTime++

// 최대 하중 무게만큼 트럭 올리기
if (waitQueue.isNotEmpty() &&
processQueue.sumOf { it.weight } + waitQueue.peek().weight <= bridgeMaxWeight
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

큐도 sum이 되는군요

) {
processQueue.add(waitQueue.poll())
}

// 트럭들 이동
processQueue.forEach { truck ->
truck.apply {
move()
if (bridgeLength < this.pos) isArrived = true
}
}

if (isArrived) {
processQueue.poll()
isArrived = false
}
}

println(usedTime)

}