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]
}
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
}
}
25 changes: 25 additions & 0 deletions Lv.1/달리기 경주.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Lv.`1`

fun solution(players: Array<String>, callings: Array<String>): Array<String> {
val rankList = players.copyOf()
val playerMap = hashMapOf<String, Int>()

players.forEachIndexed { index, player ->
playerMap[player] = index
}

callings.forEach { calledPlayer ->
playerMap[calledPlayer]?.let {
if (it > 0) {
val nextPlayer = rankList[it - 1]
rankList[it] = nextPlayer
rankList[it - 1] = calledPlayer

playerMap[calledPlayer] = it - 1
playerMap[nextPlayer] = it
}
}
}

return rankList
}
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)
}
}
26 changes: 26 additions & 0 deletions Lv.1/모의고사.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Lv.`1`

fun solution(answers: IntArray): IntArray {
val student1 = arrayOf(1, 2, 3, 4, 5)
val student2 = arrayOf(2, 1, 2, 3, 2, 4, 2, 5)
val student3 = arrayOf(3, 3, 1, 1, 2, 2, 4, 4, 5, 5)

val scores = intArrayOf(0, 0, 0)

for (i in answers.indices) {
if (answers[i] == student1[i % student1.size]) scores[0]++
if (answers[i] == student2[i % student2.size]) scores[1]++
if (answers[i] == student3[i % student3.size]) scores[2]++
}

val maxScore = scores.maxOrNull() ?: 0

val answer = mutableListOf<Int>()
for (i in scores.indices) {
if (scores[i] == maxScore) {
answer.add(i + 1)
}
}

return answer.toIntArray()
}
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
}
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