๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/Kotlin

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค • ์ฝ”ํ‹€๋ฆฐ] 2016๋…„ #12901

by ํ‚ค์œค 2023. 12. 19.

#12901

๐ŸŽ„ Question ?

https://school.programmers.co.kr/learn/courses/30/lessons/12901

class Solution {
    fun solution(a: Int, b: Int): String {
        var answer = ""
        return answer
    }
}

๐Ÿงฉ Thought Process

  1. ๊ฐ ๋‹ฌ์˜ ๋‚ ์งœ ์ˆ˜๋ฅผ month๋ผ๋Š” ๋ณ€์ˆ˜์— ์ €์žฅ
  2. ์ถœ๋ ฅํ•  ์›”ํ™”์ˆ˜๋ชฉ๊ธˆํ† ์ผ์„ ๋ฐฐ์—ด์— ์ €์žฅ.
  3. 3์›”์ด๋ฉด 1์›” 2์›”์˜ ๋‚ ์งœ์ˆ˜๋ฅผ ๋”ํ•ด์ฃผ๊ณ  ๊ทธ ๋‹ฌ์˜ ๋‚ ์งœ๋„ ๋”ํ•ด์ฃผ๊ธฐ.
    ์˜ˆ๋ฅผ๋“ค์–ด 3์›” 2์ผ์ด๋ฉด 31 + 29 +2๋ฅผ ํ•ด์ค€๋‹ค.
  4. ๊ทธ ํ›„ ์ด ๋‚ ์งœ๋ฅผ 7๋กœ ๋‚˜๋ˆ„์–ด์ฃผ๊ณ  ๊ทธ ๋‚˜๋จธ์ง€ ๊ฐ’์— ๋”ฐ๋ผ ์›”ํ™”์ˆ˜๋ชฉ๊ธˆํ‡ผ ๊ฐ’ ๋ถ€์—ฌํ•ด์ฃผ๊ธฐ.

 

๐ŸŽ€ Answer

class Solution {
    fun solution(a: Int, b: Int): String {
        var answer = "e"
        var month = arrayOf(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30)
        var m = arrayOf("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN")
        var days = 0
        for (i in 0 until a) {
            days += month[i]
        }
        days += b
        when (days%7) {
            1 -> answer = m[4]
            2 -> answer = m[5]
            3 -> answer = m[6]
            4 -> answer = m[0]
            5 -> answer = m[1]
            6 -> answer = m[2]
            0 -> answer = m[3]
        }
        return answer
    }
}

 

๐ŸŽ Result

๐Ÿ† Comment