complete 12015.kt 12738.kt 14626.kt 33985.kt 34029.kt 34060.kt 9252.py

This commit is contained in:
2025-07-13 16:13:49 +09:00
parent cd64086305
commit 7e42a7b447
7 changed files with 253 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
fun getMissingISBN(numbers: List<Int>, missingIndex: Int): Int {
val check = numbers.last()
val others = (numbers.slice(0 until 12).withIndex().sumOf {
if (it.index % 2 == 0) {
it.value
} else {
3 * it.value
}
} + check) % 10
val res = if (missingIndex % 2 == 0) {
if (others == 0) {
0
} else {
10 - others
}
} else {
if (others == 0) {
0
} else {
if ((10 - others) % 3 == 0) {
(10 - others) / 3
} else if ((20 - others) % 3 == 0) {
(20 - others) / 3
} else {
(30 - others) / 3
}
}
}
return res
}
fun main() {
var missingIndex = -1
val numbers = readln().trim().withIndex().map {
if (it.value == '*') {
missingIndex = it.index
0
} else {
it.value.digitToInt()
}
}
println(getMissingISBN(numbers, missingIndex))
}