結果
問題 | No.518 ローマ数字の和 |
ユーザー |
|
提出日時 | 2019-01-26 01:26:07 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,528 bytes |
コンパイル時間 | 3,909 ms |
コンパイル使用メモリ | 65,552 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 10:51:54 |
合計ジャッジ時間 | 4,763 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
import sequtils,strutils,mathtemplate times*(n:int,body) = (for _ in 0..<n: body)proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}proc scan(): int =while true:let k = getchar_unlocked()if k < '0': returnresult = 10 * result + k.ord - '0'.ordproc parseRoman(S:string): int =return S.replace("CM"," 900 ").replace("CD"," 400 ").replace("XC"," 90 ").replace("XL"," 40 ").replace("IX"," 9" ).replace("IV"," 4 ").replace("M"," 1000 ").replace("D"," 500 ").replace("C"," 100 ").replace("L"," 50 ").replace("X"," 10 ").replace("V"," 5 ").replace("I"," 1 ").replace(" "," ").strip().split().map(parseInt).sum()proc toRoman(n:int):string =if n < 10:if n == 4 : return "IV"if n == 9 : return "IX"if n < 4: return "I".repeat(n)return "V" & "I".repeat(n-5)if n < 100:let left = (n mod 10).toRoman()let my = n div 10if my == 4 : return "XL" & leftif my == 9 : return "XC" & leftif my < 4 : return "X".repeat(my) & leftreturn "L" & "X".repeat(my-5) & leftif n < 1000:let left = (n mod 100).toRoman()let my = n div 100if my == 4 : return "CD" & leftif my == 9 : return "CM" & leftif my < 4 : return "C".repeat(my) & leftreturn "D" & "C".repeat(my-5) & leftif n < 4000:let left = (n mod 1000).toRoman()let my = n div 1000return "M".repeat(my) & leftreturn "ERROR"let n = scan()let r = stdin.readLine.split().map(parseRoman).sum()echo r.toRoman()