-
Notifications
You must be signed in to change notification settings - Fork 0
Week5 #13
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
base: main
Are you sure you want to change the base?
Week5 #13
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,10 @@ | ||
| package Lv.`1` | ||
|
|
||
|
|
||
| fun solution(a: Int, b: Int): String { | ||
| val daysOfMonth = listOf(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) | ||
| val dayOfWeek = listOf("FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU") | ||
| val totalDays = (1 until a).sumOf { daysOfMonth[it] } + b - 1 | ||
|
|
||
| return dayOfWeek[totalDays % 7] | ||
| } | ||
| 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()) { | ||
| if (i % j == 0) { | ||
| divisorCount += 1 | ||
| if (j != i / j) { | ||
| divisorCount += 1 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (divisorCount > limit) { | ||
| answer += power | ||
| } else { | ||
| answer += divisorCount | ||
| } | ||
| } | ||
|
|
||
| return answer | ||
| } | ||
| } |
| 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) | ||
| } | ||
| "next" -> { | ||
| currentPosition = (currentPosition + 10).coerceAtMost(videoLength) | ||
| } | ||
| } | ||
|
|
||
| if (currentPosition in openingStart..openingEnd) { | ||
| currentPosition = openingEnd | ||
| } | ||
| } | ||
|
|
||
| return secondsToTime(currentPosition) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package Lv.`1` | ||
|
|
||
| fun solution(wallpaper: Array<String>): IntArray { | ||
| var lux = Int.MAX_VALUE | ||
| var luy = Int.MAX_VALUE | ||
| var rdx = 0 | ||
| var rdy = 0 | ||
|
|
||
| for (i in wallpaper.indices) { | ||
| for (j in wallpaper[i].indices) { | ||
| if (wallpaper[i][j] == '#') { | ||
| lux = minOf(lux, i) | ||
| luy = minOf(luy, j) | ||
|
|
||
| rdx = maxOf(rdx, i + 1) | ||
| rdy = maxOf(rdy, j + 1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return intArrayOf(lux, luy, rdx, rdy) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package Lv.`2` | ||
|
|
||
| fun solution(n: Int, k: Int): Int { | ||
| val converted = n.toString(k) | ||
| val parts = converted.split("0") | ||
| var count = 0 | ||
|
|
||
| for (part in parts) { | ||
| if (part.isNotEmpty() && checkPrime(part.toLong())) { | ||
| count++ | ||
| } | ||
| } | ||
|
|
||
| return count | ||
| } | ||
|
|
||
| fun checkPrime(num: Long): Boolean { | ||
| if (num < 2) return false | ||
| for (i in 2..Math.sqrt(num.toDouble()).toLong()) { | ||
| if (num % i == 0L) return false | ||
| } | ||
| return true | ||
| } | ||
|
Comment on lines
+17
to
+23
Member
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. 저도 이번에 구현하면서 깨달은건데 짝수는 2로 나눠지니 2로 나눠보고, 그 후부터는 3으로 시작해서 2씩 늘리면 시간이 완전 단축되더라구요! 물론 에라토스테네스의 체 같은 알고리즘을 쓰면 좋지만 그걸 전 외우진 못해서... ㅎㅎ...
Collaborator
Author
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. 오오오오옹..........!!!!!!!!!!!!!! 그런 부분까지,,. 진짜 코테는 너머 어려워요 ㅠㅠ |
||
| 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) | ||
| } | ||
| } |
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.
오... 상당히 깔끔하네요 코드가
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.
사실 제 코드 처음에 너무 복잡하길래 블로그에서 이거저것........눈팅했읍니다