結果

問題 No.518 ローマ数字の和
ユーザー maimai
提出日時 2017-05-28 22:18:01
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 2,450 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-09-21 15:33:12
合計ジャッジ時間 2,966 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def scan; gets.split.map(&:to_i); end

def say(w)
    puts w;exit
end

def revert(str)
    val = 0
    if str=~/^(M+)/
        val += $1.size*1000
        str=str[$1.size..-1]
    end
    if str=~/^(CM)/
        val += 900
        str=str[$1.size..-1]
    end
    if str=~/^(DCCC)/
        val += 800
        str=str[$1.size..-1]
    end
    if str=~/^(DCC)/
        val += 700
        str=str[$1.size..-1]
    end
    if str=~/^(DC)/
        val += 600
        str=str[$1.size..-1]
    end
    if str=~/^(D)/
        val += 500
        str=str[$1.size..-1]
    end
    if str=~/^(CD)/
        val += 400
        str=str[$1.size..-1]
    end
    if str=~/^(CCC)/
        val += 300
        str=str[$1.size..-1]
    end
    if str=~/^(CC)/
        val += 200
        str=str[$1.size..-1]
    end
    if str=~/^(C)/
        val += 100
        str=str[$1.size..-1]
    end
    if str=~/^(XC)/
        val += 90
        str=str[$1.size..-1]
    end
    if str=~/^(LXXX)/
        val += 80
        str=str[$1.size..-1]
    end
    if str=~/^(LXX)/
        val += 70
        str=str[$1.size..-1]
    end
    if str=~/^(LX)/
        val += 60
        str=str[$1.size..-1]
    end
    if str=~/^(L)/
        val += 50
        str=str[$1.size..-1]
    end
    if str=~/^(XL)/
        val += 40
        str=str[$1.size..-1]
    end
    if str=~/^(XXX)/
        val += 30
        str=str[$1.size..-1]
    end
    if str=~/^(XX)/
        val += 20
        str=str[$1.size..-1]
    end
    if str=~/^(X)/
        val += 10
        str=str[$1.size..-1]
    end
    if str=~/^(IX)/
        val += 9
        str=str[$1.size..-1]
    end
    if str=~/^(VIII)/
        val += 8
        str=str[$1.size..-1]
    end
    if str=~/^(VII)/
        val += 7
        str=str[$1.size..-1]
    end
    if str=~/^(VI)/
        val += 6
        str=str[$1.size..-1]
    end
    if str=~/^(V)/
        val += 5
        str=str[$1.size..-1]
    end
    if str=~/^(IV)/
        val += 4
        str=str[$1.size..-1]
    end
    if str=~/^(I+)/
        val += $1.size
        str=str[$1.size..-1]
    end
    val
end
def convert(val)
    say "ERROR" if 4000<= val
    str = 'M'*(val/1000)+'C'*((val%1000)/ 100)+'X'*((val%100)/ 10)+'I'*((val%10))
    str.gsub('CCCCC','D').gsub('XXXXX','L').gsub('IIIII','V').gsub('DCCC','CM').gsub('CCCC','CD').gsub('LXXXX','XC').gsub('XXXX','XL').gsub('VIIII','IX').gsub('IIII','IV')
end

gets
puts convert(gets.split.map{|e|revert(e)}.inject(:+))
0