結果

問題 No.518 ローマ数字の和
ユーザー bluemeganebluemegane
提出日時 2021-05-08 20:23:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 2,171 bytes
コンパイル時間 4,786 ms
コンパイル使用メモリ 111,356 KB
実行使用メモリ 24,508 KB
最終ジャッジ日時 2023-10-17 05:57:31
合計ジャッジ時間 5,787 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    public static Dictionary<string, int> d, d2;
    public static Dictionary<int ,string > d3, d4;
    static void Main()
    {
        var a = new string[] { "I", "V", "X", "L", "C", "D", "M" };
        var a2 = new int[] { 1, 5, 10, 50, 100, 500, 1000 };
        var b = new string[] { "IV", "IX", "XL", "XC", "CD", "CM" };
        var b2 = new int[] { 4, 9, 40, 90, 400, 900 };
        d = new Dictionary<string, int>();
        d2 = new Dictionary<string, int>();
        d3 = new Dictionary<int, string>();
        d4 = new Dictionary<int, string>();
        for (int i = 0; i < a.Length; i++) { d[a[i]] = a2[i]; d3[a2[i]] = a[i]; }
        for (int i = 0; i < b.Length; i++) { d2[b[i]] = b2[i]; d4[b2[i]] = b[i]; }
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var sum = 0;
        foreach (var x in line) sum += calc(x);
        getAns(sum);

    }
    static int calc(string s)
    {
        var res = 0;
        foreach (var x in d2)
        {
            var sL = s.Length;
            s = s.Replace(x.Key, "");
            var sL2 = s.Length;
            res += (sL - sL2) / 2 * x.Value;
        }
        foreach (var x in s) res += d[x.ToString()];
        return res;
    }
    static void getAns(int t)
    {
        if (t > 3999) { Console.WriteLine("ERROR"); return; }
        var s = "";
        var a = t / 1000;
        s += new string('M', a);
        t %= 1000;
        var b = t / 100;
        if (b == 9) s += d4[900];
        else if (b >= 5) s += d3[500] + new string('C', b % 5);
        else if (b == 4) s += d4[400];
        else s += new string('C', b);
        t %= 100;
        var c = t / 10;
        if (c == 9) s += d4[90];
        else if (c >= 5) s += d3[50] + new string('X', c % 5);
        else if (c == 4) s += d4[40];
        else s += new string('X', c);
        t %= 10;
        if (t == 9) s += d4[9];
        else if (t >= 5) s += d3[5] + new string('I', t % 5);
        else if (t == 4) s += d4[4];
        else s += new string('I', t);
        Console.WriteLine(s);
    }
}
0