#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
- ๊ฐ ๋ฌ์ ๋ ์ง ์๋ฅผ month๋ผ๋ ๋ณ์์ ์ ์ฅ
- ์ถ๋ ฅํ ์ํ์๋ชฉ๊ธํ ์ผ์ ๋ฐฐ์ด์ ์ ์ฅ.
- 3์์ด๋ฉด 1์ 2์์ ๋ ์ง์๋ฅผ ๋ํด์ฃผ๊ณ ๊ทธ ๋ฌ์ ๋ ์ง๋ ๋ํด์ฃผ๊ธฐ.
์๋ฅผ๋ค์ด 3์ 2์ผ์ด๋ฉด 31 + 29 +2๋ฅผ ํด์ค๋ค. - ๊ทธ ํ ์ด ๋ ์ง๋ฅผ 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
'Algorithm > Kotlin' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] Generating Prime Number #12977 (0) | 2023.12.29 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ๋ชจ์๊ณ ์ฌ ์์ ํ์ #42840 (0) | 2023.12.27 |
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ์นด๋ ๋ญ์น #159994 (0) | 2023.12.19 |
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ๋ช ์์ ์ ๋น(1) #138477 (0) | 2023.12.14 |
[ํ๋ก๊ทธ๋๋จธ์ค โข ์ฝํ๋ฆฐ] ์ฝ๋ผ ๋ฌธ์ #132267 (0) | 2023.12.13 |