結果

問題 No.518 ローマ数字の和
ユーザー NoNo
提出日時 2016-08-10 01:14:58
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,613 bytes
コンパイル時間 2,662 ms
コンパイル使用メモリ 107,904 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-24 23:08:49
合計ジャッジ時間 4,222 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
18,944 KB
testcase_01 AC 28 ms
18,944 KB
testcase_02 AC 27 ms
18,816 KB
testcase_03 AC 27 ms
18,688 KB
testcase_04 AC 28 ms
18,816 KB
testcase_05 AC 27 ms
18,688 KB
testcase_06 AC 28 ms
18,816 KB
testcase_07 AC 28 ms
18,816 KB
testcase_08 AC 28 ms
18,944 KB
testcase_09 AC 28 ms
18,816 KB
testcase_10 AC 29 ms
18,944 KB
testcase_11 AC 29 ms
18,944 KB
testcase_12 AC 28 ms
19,072 KB
testcase_13 AC 28 ms
19,072 KB
testcase_14 AC 27 ms
18,944 KB
testcase_15 AC 29 ms
18,816 KB
testcase_16 AC 27 ms
18,944 KB
testcase_17 AC 27 ms
19,072 KB
testcase_18 WA -
testcase_19 AC 28 ms
18,816 KB
testcase_20 AC 28 ms
18,944 KB
testcase_21 AC 27 ms
18,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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;
        }
    }
}
0