結果
| 問題 |
No.518 ローマ数字の和
|
| コンテスト | |
| ユーザー |
6soukiti29
|
| 提出日時 | 2017-06-22 08:30:15 |
| 言語 | Nim (2.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 799 bytes |
| コンパイル時間 | 3,557 ms |
| コンパイル使用メモリ | 70,144 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-30 01:28:53 |
| 合計ジャッジ時間 | 4,359 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'sequtils' [UnusedImport]
ソースコード
import strutils,sequtils,tables
var
N : int
R : seq[string]
cnt : int
Roman = {'I': 1, 'V': 5, 'X': 10, 'L':50, 'C':100,'D' :500 ,'M':1000}.toTable
cnt = 0
N = stdin.readline.parseInt
R = stdin.readline.strip.split
for r in R:
for i in 0..r.len-2:
if Roman[r[i]] < Roman[r[i + 1]]:
cnt -= Roman[r[i]]
else:
cnt += Roman[r[i]]
cnt += Roman[r[^1]]
if cnt > 3999:
echo "ERROR"
else:
type rom = tuple[R : string, num :int]
var
ans = ""
rom_num : array[13,rom]
rom_num = [("M",1000),("CM",900),("D",500),("CD",400),("C",100),("XC",90),("L",50),("XL",40),("X",10),("IX",9),("V",5),("IV",4),("I",1)]
for r in rom_num:
while cnt >= r[1]:
ans &= r[0]
cnt -= r[1]
echo ans
6soukiti29