-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 -> | ||
if (lastChar != curChar) { | ||
if (curChar in existedWordList) { | ||
return@repeat | ||
} else { | ||
existedWordList.add(curChar) | ||
lastChar = curChar | ||
} | ||
} | ||
} | ||
groupWordCnt++ | ||
} | ||
|
||
println(groupWordCnt) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package hyunsoo.`12week` | ||
|
||
/** | ||
* <문제> | ||
* [수리공 항승](https://www.acmicpc.net/problem/1449) | ||
* | ||
* 물새는 곳을 하나씩 막아보자앗..!! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 가즈앗..!! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정말 스케줄링 하는 것처럼 구현하셔서 챌린지가 떠올랐습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
첫번째 단어를 앞에서 미리 처리해주고 drop처리 해주신 부분 좋네요!