結果

問題 No.564 背の順
ユーザー 💕💖💞💕💖💞
提出日時 2017-09-09 01:08:24
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 10,749 ms
コンパイル使用メモリ 446,636 KB
実行使用メモリ 60,660 KB
最終ジャッジ日時 2024-04-30 15:44:49
合計ジャッジ時間 15,374 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 285 ms
60,608 KB
testcase_01 AC 284 ms
60,444 KB
testcase_02 AC 292 ms
60,644 KB
testcase_03 AC 291 ms
60,612 KB
testcase_04 AC 290 ms
60,496 KB
testcase_05 AC 298 ms
60,540 KB
testcase_06 AC 308 ms
60,640 KB
testcase_07 AC 292 ms
60,524 KB
testcase_08 AC 293 ms
60,660 KB
testcase_09 AC 288 ms
60,476 KB
testcase_10 AC 290 ms
60,476 KB
testcase_11 AC 290 ms
60,368 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