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

Week4 #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions Lv.1/기사단원의 무기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package Lv.`1`

class Solution4 {
fun solution(number: Int, limit: Int, power: Int): Int {
var answer: Int = 0

for (i in 1..number) {
var divisorCount = 0

for (j in 1..Math.sqrt(i.toDouble()).toInt()) {

Choose a reason for hiding this comment

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

오 Math 사용하셨군요👍👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

뭔가 불편한 코드,.,...

if (i % j == 0) {
divisorCount += 1
if (j != i / j) {
divisorCount += 1
}
}
}

if (divisorCount > limit) {
answer += power
} else {
answer += divisorCount
}
}

return answer
}
}
42 changes: 42 additions & 0 deletions Lv.1/동영상 재생기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Lv.`1`

class Solution5 {
fun solution(videoLen: String, pos: String, opStart: String, opEnd: String, commands: Array<String>): String {
fun timeToSeconds(time: String): Int {
val parts = time.split(":")
return parts[0].toInt() * 60 + parts[1].toInt()
}

fun secondsToTime(seconds: Int): String {
val minutes = seconds / 60
val secs = seconds % 60
return String.format("%02d:%02d", minutes, secs)
}

val videoLength = timeToSeconds(videoLen)
val openingStart = timeToSeconds(opStart)
val openingEnd = timeToSeconds(opEnd)
var currentPosition = timeToSeconds(pos)

if (currentPosition in openingStart..openingEnd) {
currentPosition = openingEnd
}

for (command in commands) {
when (command) {
"prev" -> {
currentPosition = (currentPosition - 10).coerceAtLeast(0)

Choose a reason for hiding this comment

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

코틀린에는 coerceAt 이라는 함수가 제공되네요 신기합니다 ㅋㅎㅋㅎ

}
"next" -> {
currentPosition = (currentPosition + 10).coerceAtMost(videoLength)
}
}

if (currentPosition in openingStart..openingEnd) {
currentPosition = openingEnd
}
}

return secondsToTime(currentPosition)
}
}
22 changes: 22 additions & 0 deletions Lv.2/이진 변환 반복하기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Lv.`2`

class Solution {
fun solution(s: String): IntArray {
var count = 0
var zeroCount = 0
var currentString = s

while (currentString != "1") {
val zeros = currentString.count { it == '0' }
zeroCount += zeros

val length = currentString.length - zeros

currentString = Integer.toBinaryString(length)

count++
}

return intArrayOf(count, zeroCount)
}
}