Skip to content
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
10 changes: 10 additions & 0 deletions Lv.1/2016년.kt
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]
}
Comment on lines +4 to +10
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
Collaborator Author

Choose a reason for hiding this comment

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

사실 제 코드 처음에 너무 복잡하길래 블로그에서 이거저것........눈팅했읍니다

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()) {
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)
}
"next" -> {
currentPosition = (currentPosition + 10).coerceAtMost(videoLength)
}
}

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

return secondsToTime(currentPosition)
}
}
22 changes: 22 additions & 0 deletions Lv.1/바탕화면 정리.kt
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)
}
23 changes: 23 additions & 0 deletions Lv.2/k진수에서 소수 개수 구하기.kt
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
Copy link
Member

Choose a reason for hiding this comment

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

저도 이번에 구현하면서 깨달은건데 짝수는 2로 나눠지니 2로 나눠보고, 그 후부터는 3으로 시작해서 2씩 늘리면 시간이 완전 단축되더라구요!

물론 에라토스테네스의 체 같은 알고리즘을 쓰면 좋지만 그걸 전 외우진 못해서... ㅎㅎ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

오오오오옹..........!!!!!!!!!!!!!! 그런 부분까지,,. 진짜 코테는 너머 어려워요 ㅠㅠ

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)
}
}
2 changes: 1 addition & 1 deletion kotlin_2/오픈채팅방.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kotlin_2

class Solution {
fun solution(record: Array<String>): Array<Any> {
fun solution(record: Int, intArrayOf: IntArray, intArrayOf1: IntArray): Array<Any> {
var member: MutableMap<String, String> = mutableMapOf()

record.forEach {
Expand Down