結果
| 問題 | 
                            No.518 ローマ数字の和
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-06-02 13:17:55 | 
| 言語 | Python2  (2.7.18)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 13 ms / 2,000 ms | 
| コード長 | 650 bytes | 
| コンパイル時間 | 172 ms | 
| コンパイル使用メモリ | 6,912 KB | 
| 実行使用メモリ | 6,272 KB | 
| 最終ジャッジ日時 | 2024-09-21 22:10:16 | 
| 合計ジャッジ時間 | 1,154 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 | 
ソースコード
#yuki_518
l=[(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'),(50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I')]
def roman2int(s):
 res=0
 a=[]
 for i in range(len(s)):
  for j in xrange(len(l)):
   if s[i]==l[j][1]:
    a.append(l[j][0])
 a.append(0)
 for i in range(len(s)):
  if a[i]>=a[i+1]:
   res+=a[i]
  else:
   res-=a[i]
 return res
def int2roman(n):
 res = ''
 for num, roman in l:
  res+=roman*(n/num)
  n%=num
 return res
n=int(raw_input())
lr=raw_input().split()
li=[]
for i in xrange(n):
 li.append(roman2int(lr[i]))
sm=sum(li)
if sm>3999:
 print 'ERROR'
else:
 print int2roman(sm)