와 생각보다 오래 걸렸습니다.
이게 테스트 케이스는 모두 맞고, 실제 채점은 틀려버리니깐 더 헷갈리네요.
package seventyFirst
class `lv1 개인 정보 수집 기간` {
class Solution {
fun solution(today: String, terms: Array<String>, privacies: Array<String>): IntArray {
// 오늘 날짜
val todaySplit = today.split('.')
val todayYear = todaySplit[0].toInt()
val todayMonth = todaySplit[1].toInt()
val todayDay = todaySplit[2].toInt()
// 답 저장 배열
val ans = arrayListOf<Int>()
// map에 약관 기간 저장
val termsMap = mutableMapOf<String,Int>()
for (index in terms.indices){
val split = terms[index].split(' ')
termsMap[split.first()] = split.last().toInt()
}
for (index in privacies.indices){
val split = privacies[index].split(' ')
val daySplit = split.first().split('.')
// 날짜, 약관 기간
var year = daySplit[0].toInt()
var month = daySplit[1].toInt()
var day = daySplit[2].toInt()
val termDay = termsMap[split.last()]!!
// 날짜 변환
year += termDay / 12
month += termDay % 12
if (month > 12){
year += 1
month -= 12
}
if (day == 1){
if (month == 1){
month = 12
year -= 1
}
else{
month -= 1
}
day = 28
}
else{
day -= 1
}
if (todayYear > year) {
ans.add(index + 1)
continue
}
if (todayYear == year && todayMonth > month){
ans.add(index + 1)
continue
}
if (todayYear == year && todayMonth == month && todayDay > day){
ans.add(index + 1)
continue
}
}
val arr = IntArray(ans.size)
for (index in ans.indices)
arr[index] = ans[index]
return arr
}
}
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[2023-06-16] [프로그래머스 lv2] 이모티콘 할인행사 (Kotlin) (0) | 2023.06.16 |
---|---|
[2023-06-16] [프로그래머스 lv2] 택배 배달과 수거하기 (Kotlin) (0) | 2023.06.16 |
[2023-06-14] [프로그래머스 lv1] 카드 뭉치 (Kotlin) (0) | 2023.06.14 |
[2023-06-14] [프로그래머스 lv1] 대충 만든 자판 (Kotlin) (0) | 2023.06.14 |
[2023-06-13] [프로그래머스 lv1] 덧칠하기 (Kotlin) (0) | 2023.06.13 |
댓글