結果
| 問題 |
No.518 ローマ数字の和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-09 02:57:42 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 569 bytes |
| コンパイル時間 | 44 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-10-12 00:28:19 |
| 合計ジャッジ時間 | 2,921 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | AC * 2 WA * 17 |
コンパイルメッセージ
Syntax OK
ソースコード
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) })