백준 1431번
https://www.acmicpc.net/problem/1431
import java.io.*
// input
private var br = System.`in`.bufferedReader()
// variables
private var N = 0
private lateinit var arr: Array<String>
fun main() {
val bw = System.out.bufferedWriter()
input()
bw.write(solve())
bw.close()
} // End of main()
private fun solve(): String {
val sb = StringBuilder()
arr.sortWith(
compareBy(
{ it.length },
{ it.calc() },
{ it }
)
)
arr.forEach {
sb.append(it).append('\n')
}
return sb.toString()
} // End of solve()
private fun String.calc(): Int {
return this.filter { it.isDigit() }.sumOf { it - '0' }
} // End of calc()
private fun input() {
N = br.readLine().toInt()
arr = Array<String>(N) {
br.readLine()
}
} // End of input()