結果
問題 | No.518 ローマ数字の和 |
ユーザー |
|
提出日時 | 2017-05-28 21:46:29 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 89 ms / 2,000 ms |
コード長 | 812 bytes |
コンパイル時間 | 35 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-09-21 15:22:06 |
合計ジャッジ時間 | 2,565 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
Main.rb:37: warning: assigned but unused variable - n Syntax OK
ソースコード
@h = {?I => 1, ?V => 5, ?X => 10, ?L => 50, ?C => 100, ?D => 500, ?M => 1000}@h2 = @h.invertdef hoge(r)m = r.sizeres = @h[r[m - 1]](m-1).times do |i|if @h[r[i]] < @h[r[i + 1]]res -= @h[r[i]]elseres += @h[r[i]]endendreturn resenddef foo(x)return "ERROR" if x >= 4000res = ""d = 1while x > 0if x % 10 == 9res = @h2[d] + @h2[d * 10] + reselsif x % 10 == 4res = @h2[d] + @h2[d * 5] + reselsif x % 10 > 4res = @h2[d * 5] + @h2[d] * (x % 10 - 5) + reselseres = @h2[d] * (x % 10) + resendx /= 10d *= 10endreturn resendn = gets.to_iputs foo(gets.chomp.split.map{|r| hoge(r)}.inject(:+))