結果

問題 No.564 背の順
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-09 01:08:24
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 13,116 ms
コンパイル使用メモリ 445,736 KB
実行使用メモリ 60,612 KB
最終ジャッジ日時 2024-11-20 11:54:21
合計ジャッジ時間 18,462 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 348 ms
60,432 KB
testcase_01 AC 351 ms
60,288 KB
testcase_02 AC 351 ms
60,560 KB
testcase_03 AC 348 ms
60,464 KB
testcase_04 AC 351 ms
60,264 KB
testcase_05 AC 354 ms
60,556 KB
testcase_06 AC 351 ms
60,612 KB
testcase_07 AC 345 ms
60,340 KB
testcase_08 AC 354 ms
60,508 KB
testcase_09 AC 343 ms
60,344 KB
testcase_10 AC 342 ms
60,196 KB
testcase_11 AC 346 ms
60,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:11: warning: parameter 'args' is never used
fun main( args : Array<String> ) {
          ^
Main.kt:12:16: warning: name shadowed: h
    val (type, h) = x
               ^

ソースコード

diff #

fun main( args : Array<String> ) {
  val (h, n) = readLine()!!.split(" ").map { it.toInt() }
  val ns = (1..n-1).map {
    readLine()!!.toInt()
  }.map { 
    Pair("Other", it)
  }.toMutableList()
  ns.add( Pair("Target", h) )
  ns.sortedBy{ 
    it.second * -1
  }.mapIndexed { i,x ->
    val (type, h) = x
    Triple(type, i+1, h)
  }.filter {
    it.first == "Target"
  }.let { 
    val rank = it.first().second 
    val last = rank.toString().toList().last().toString()
    when {
      last == "1" -> println("${rank}st")
      last == "2" -> println("${rank}nd")
      last == "3" -> println("${rank}rd")
      else -> println("${rank}th")
    }
  }
}
0