結果

問題 No.39 桁の数字を入れ替え
ユーザー バカらっくバカらっく
提出日時 2019-09-07 21:01:48
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 293 ms / 5,000 ms
コード長 594 bytes
コンパイル時間 14,000 ms
コンパイル使用メモリ 414,080 KB
実行使用メモリ 53,052 KB
最終ジャッジ日時 2023-09-09 11:25:58
合計ジャッジ時間 21,289 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 288 ms
52,732 KB
testcase_01 AC 283 ms
52,868 KB
testcase_02 AC 283 ms
52,744 KB
testcase_03 AC 284 ms
52,736 KB
testcase_04 AC 292 ms
52,840 KB
testcase_05 AC 283 ms
52,820 KB
testcase_06 AC 284 ms
53,052 KB
testcase_07 AC 293 ms
52,796 KB
testcase_08 AC 292 ms
52,892 KB
testcase_09 AC 291 ms
52,700 KB
testcase_10 AC 289 ms
52,800 KB
testcase_11 AC 285 ms
52,824 KB
testcase_12 AC 289 ms
52,724 KB
testcase_13 AC 287 ms
52,712 KB
testcase_14 AC 287 ms
52,848 KB
testcase_15 AC 288 ms
52,780 KB
testcase_16 AC 289 ms
52,844 KB
testcase_17 AC 289 ms
52,840 KB
testcase_18 AC 287 ms
52,776 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:5:42: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Char
        val idx = inpt.indexOf(inpt.max()!!)
                                         ^

ソースコード

diff #

fun main(arr:Array<String>) {
    val inpt = readLine()!!.map { it }.toMutableList()
    val ans = mutableListOf<Char>()
    (1..inpt.size).forEach {
        val idx = inpt.indexOf(inpt.max()!!)
        if(idx == 0)  {
            ans.add(inpt[0])
            inpt.removeAt(0)
        } else {
            val lastIndex = inpt.lastIndexOf(inpt[idx])
            val tmp = inpt[lastIndex]
            inpt[lastIndex] = inpt[0]
            inpt[0] = tmp
            ans.addAll(inpt)
            println(ans.joinToString(""))
            return
        }
    }
    println(ans.joinToString(""))

}
0