import java.util.*
fun main(args: Array<String>) = with(Scanner(System.`in`)) {
val findSeconds: (Char) -> Int = { c: Char ->
val tn1 = when (val code: Int = c.code - 65) {
18, 21, 24 -> code - 1
25 -> code - 2
else -> code
}
val tempNumber = tn1 / 3 + 2
val requiredSeconds = tempNumber - 1 + 2
requiredSeconds
}
val str = nextLine()
val result = str.fold(0) { acc, c ->
acc + findSeconds(c)
}
println(result)
}
시발 코드 존나 기네 ㅋ
아래는 일부러 줄인 코드. 가독성 ㅎㅌㅊ. 알고리즘은 그냥 ㅍㅌㅊ
fun main(args: Array<String>) = with(Scanner(System.`in`)) {
println(nextLine().fold(0) { acc, c ->
acc + when (val code: Int = c.code - 65) {
18, 21, 24 -> code - 1
25 -> code - 2
else -> code
} / 3 + 2 - 1 + 2
})
}
코틀린이라 추천드립니다!