結果
問題 | No.518 ローマ数字の和 |
ユーザー |
![]() |
提出日時 | 2016-08-10 01:14:58 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,613 bytes |
コンパイル時間 | 2,711 ms |
コンパイル使用メモリ | 108,288 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-11-07 08:24:22 |
合計ジャッジ時間 | 4,412 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace yukikoda{class Program{static void Main(string[] args){int n = int.Parse(Console.ReadLine());string[] s = Console.ReadLine().Split();string a = "";foreach (var item in s){a = a + Convert(item);}string ans = "";int cnt = a.Where(x => x == 'M').Count();while (cnt > 0){ans += "M";cnt--;}cnt = a.Where(x => x == 'D').Count();while (cnt > 0){ans += "D";cnt--;}cnt = a.Where(x => x == 'C').Count();while (cnt > 0){ans += "C";cnt--;}cnt = a.Where(x => x == 'L').Count();while (cnt > 0){ans += "L";cnt--;}cnt = a.Where(x => x == 'X').Count();while (cnt > 0){ans += "X";cnt--;}cnt = a.Where(x => x == 'V').Count();while (cnt > 0){ans += "V";cnt--;}cnt = a.Where(x => x == 'I').Count();while (cnt > 0){ans += "I";cnt--;}ans = ans.Replace("IIIII", "V");ans = ans.Replace("VV", "X");ans = ans.Replace("XXXXX", "L");ans = ans.Replace("LL", "C");ans = ans.Replace("CCCCC", "D");ans = ans.Replace("DD", "M");ans = ans.Replace("DCCCC", "CM");ans = ans.Replace("CCCC", "CD");ans = ans.Replace("LXXXX", "XC");ans = ans.Replace("XXXX", "XL");ans = ans.Replace("VIIII", "IX");ans = ans.Replace("IIII", "IV");if (ans.Where(x => x == 'M').Count() >= 4) ans = "ERROR";Console.WriteLine(ans);Console.ReadLine();}static string Convert(string r){r = r.Replace("CM", "DCCCC");r = r.Replace("CD", "CCCC");r = r.Replace("XC", "LXXXX");r = r.Replace("XL", "XXXX");r = r.Replace("IX", "VIIII");r = r.Replace("IV", "IIII");return r;}}}