on board: IntelliJ IDEA Community Edition 2020.1.1 x64
beautify: ctrl+alt+L
// sort,very standard
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles
private fun readArray() = readStrings().map { it.toInt() }.toIntArray() // list of ints
var INF = 1_000_000_000 + 10
fun main() {
    var t = readInt()
    while (t-- > 0) {
        var n = readInt()
        var a = readInts()
        a.sorted()
        var sum = 0
        var minn = Pair(INF, 0)
        for (i in a.indices) {
            if (a[i] > 0) {
                sum += a[i]
                if (a[i] < minn.first)
                    minn = Pair(a[i], i)
            }
            if (a[i] < 0 && -a[i] < minn.first)
                minn = Pair(-a[i], i)
        }
        println(sum - minn.first)
        var ans = mutableListOf<Int>()
        for (i in a.indices) {
            if ((a[i] > 0 && i != minn.second) || (a[i] < 0 && i == minn.second))
                ans.add(1)
            else
                ans.add(0)
        }
        println(ans.joinToString(""))
    }
}
//class
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles
fun main() {
    var t = readInt()
    repeat(t) {
        var n = readInt()
        println(n.round().convert())
    }
}
fun Int.convert(): String {
    return when {
        this >= 1000000 -> {
            "${this / 1000000}M"
        }
        this >= 1000 -> {
            "${this / 1000}K"
        }
        else -> {
            "$this"
        }
    }
}
fun Int.round(): Int {
    return when {
        this >= 1000000 -> {
            (this + 500000) / 1000000 * 1000000
        }
        this >= 1000 -> {
            (this + 500) / 1000 * 1000
        }
        else -> {
            this
        }
    }
}
//import
import kotlin.math.roundToInt
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles
fun main() {
    var t = readInt()
    repeat(t) {
        var n = readInt()
        solve(n)
    }
}
fun solve(n: Int) {
    if (n >= 999500) {
        println((n / 1000000.0).roundToInt().toString() + "M")
    } else if (n >= 1000) {
        println((n / 1000.0).roundToInt().toString() + "K")
    } else println(n)
}
原文:https://www.cnblogs.com/reshuffle/p/12918224.html