結果

問題 No.518 ローマ数字の和
ユーザー 0w10w1
提出日時 2017-08-09 02:57:42
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 569 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-20 05:28:04
合計ジャッジ時間 2,959 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 86 ms
12,160 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 86 ms
12,288 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
R = gets.chomp.split

def value c
  case c
  when ?I then 1
  when ?V then 5
  when ?X then 10
  when ?L then 50
  when ?C then 100
  when ?D then 500
  when ?M then 1000
  end
end

def tot s
  s.chars.inject(0) { |a, b| a + value(b) }
end

def rev v
  s = ""
  (s << ?M; v -= 1000) until v < 1000
  (s << ?D; v -= 500) until v < 500
  (s << ?C; v -= 100) until v < 100
  (s << ?L; v -= 50) until v < 50
  (s << ?X; v -= 10) until v < 10
  (s << ?V; v -= 5) until v < 5
  (s << ?I; v -= 1) until v < 1
  s
end

puts rev(R.inject(0) { |a, b| a + tot(b) })
0