結果

問題 No.518 ローマ数字の和
ユーザー mitsuomitsuo
提出日時 2017-06-21 12:45:43
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 09:01:08
合計ジャッジ時間 1,098 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 10 ms
6,940 KB
testcase_03 AC 11 ms
6,944 KB
testcase_04 AC 11 ms
6,940 KB
testcase_05 AC 11 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 11 ms
6,944 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 11 ms
6,940 KB
testcase_16 WA -
testcase_17 AC 11 ms
6,944 KB
testcase_18 WA -
testcase_19 AC 11 ms
6,940 KB
testcase_20 WA -
testcase_21 AC 10 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

def ator(i):
    s = ""
    t4 = i // 1000
    t35 = (i % 1000) // 500
    t3 = (i % 500) // 100
    t25 = (i % 100) // 50
    t2 = (i % 50) // 10
    t15 = i % 10 // 5
    t1 = i % 5

    s += "M" * t4

    if t35 == 1 and t3 == 4:
        s += "CM"
    elif t3 == 4:
        s += "CD"
    else:
        s += "D" * t35 + "C" * t3

    if t25 == 1 and t2 == 4:
        s += "XC"
    elif t2 == 4:
        s += "XL"
    else:
        s += "L" * t25 + "X" * t2

    if t15 == 1 and t1 == 4:
        s += "IX"
    elif t1 == 4:
        s += "IV"
    else:
        s += "V" * t15 + "I" * t1

    return s

def rtoa(s):
    tbx = {'IV' : 4, 'IX' : 9, 'XL' : 40, 'XC' : 90, 'CD' : 400, 'CM' : 900}
    tb = {'I' : 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000}

    sum = 0
    for k in tbx:
        if k in s:
            print s, k, tbx[k]
            sum += tbx[k]
            s = s.replace(k, "")

    for c in s:
        sum += tb[c]
    return sum



def solve(input):
    roma = input[1].split()
    sum = 0
    for r in roma:
        sum += rtoa(r)

    if sum < 4000:
        return ator(sum)
    else:
        return "ERROR"
    pass

if __name__ == "__main__":
    input = []
    input += [raw_input()]
    input += [raw_input()]

    print solve(input)
0