結果

問題 No.564 背の順
ユーザー mesh1nek0x0mesh1nek0x0
提出日時 2018-08-15 22:11:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 378 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 11,888 KB
実行使用メモリ 16,072 KB
最終ジャッジ日時 2023-10-24 17:32:39
合計ジャッジ時間 1,821 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
16,072 KB
testcase_01 AC 83 ms
16,072 KB
testcase_02 AC 83 ms
16,072 KB
testcase_03 AC 82 ms
16,072 KB
testcase_04 AC 86 ms
16,072 KB
testcase_05 AC 83 ms
16,072 KB
testcase_06 AC 82 ms
16,072 KB
testcase_07 AC 82 ms
16,072 KB
testcase_08 AC 82 ms
16,072 KB
testcase_09 AC 84 ms
16,072 KB
testcase_10 AC 83 ms
16,072 KB
testcase_11 AC 82 ms
16,072 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/bin/ruby
H, N = gets.chomp.split(' ')

classmate = [H]
(N.to_i - 1).times do
  classmate.push(gets.chomp)
end

sorted = classmate.sort { |val1, val2| val2.to_i <=> val1.to_i }

rank = sorted.index(H).to_i + 1

if rank.to_s.match(/1$/)
  puts "#{rank}st"
elsif rank.to_s.match(/2$/)
  puts "#{rank}nd"
elsif rank.to_s.match(/3$/)
  puts "#{rank}rd"
else
  puts "#{rank}th"
end
0