結果

問題 No.518 ローマ数字の和
ユーザー char134217728char134217728
提出日時 2017-08-20 13:17:05
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-22 18:12:55
合計ジャッジ時間 3,534 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

m = {
  "" => 0,
  "I" => 1,
  "II" => 2,
  "III" => 3,
  "IV" => 4,
  "V" => 5,
  "VI" => 6,
  "VII" => 7,
  "VIII" => 8,
  "IX" => 9,
  "X" => 10,
  "XX" => 20,
  "XXX" => 30,
  "XL" => 40,
  "L" => 50,
  "LX" => 60,
  "LXX" => 70,
  "LXXX" => 80,
  "XC" => 90,
  "C" => 100,
  "CC" => 200,
  "CCC" => 300,
  "CD" => 400,
  "D" => 500,
  "DC" => 600,
  "DCC" => 700,
  "DCCC" => 800,
  "CM" => 900,
  "M" => 1000,
  "MM" => 2000,
  "MMM" => 3000
}
gets
s = 0
gets.split(" ").each do |_s|
  _s =~ /\A(M*)(CM|D|CD|)(C*)(XC|L|XL|)(X*)(IX|V|IV|)(I*)\z/
  (1..7).each do |i|
    s += m[$~[i]]
  end
end
if s > 3999
  puts :ERROR
  exit
end
m = m.invert
t = ""
[1000, 100, 10, 1].each do |i|
  t << m[s / i * i]
  s %= i
end
puts t
0