結果

問題 No.518 ローマ数字の和
ユーザー 14番14番
提出日時 2017-05-28 22:02:27
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,319 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 112,752 KB
実行使用メモリ 24,232 KB
最終ジャッジ日時 2023-10-21 14:12:10
合計ジャッジ時間 2,540 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 25 ms
24,176 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 24 ms
24,176 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 25 ms
24,176 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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        int MaxLimit = 3999;

        int itemCount = int.Parse(Reader.ReadLine());
        string[] inpt = new string[itemCount];

        inpt = Reader.ReadLine().Split(' ');

        int ans = 0;
        foreach (string roman in inpt)
        {
            ans += RomanToArabic(roman);
        }
        if (ans > MaxLimit)
        {
            Console.WriteLine("ERROR");
        }
        else
        {
            Console.WriteLine(ans);
        }
    }

    private int RomanToArabic(string inpt)
    {
        int idx = -1;
        int ans = 0;
        while (++idx < inpt.Length)
        {
            if (idx < inpt.Length - 1)
            {
                if (Conv(inpt[idx]) < Conv(inpt[idx+1]))
                {
                    ans += Conv(inpt[idx + 1]) - Conv(inpt[idx]);
                    idx++;
                    continue;
                }
            }
            ans += Conv(inpt[idx]);
        }
        return ans;

    }

    private int Conv(char c)
    {
        // I = 1、V = 5、X = 10、L = 50、C = 100、D = 500、M = 1000

        switch (c)
        {
            case 'I':
                return 1;
            case 'V':
                return 5;
            case 'X':
                return 10;
            case 'L':
                return 50;
            case 'C':
                return 100;
            case 'D':
                return 500;
            default:
                return 1000;
        }
    }




    public class Reader
    {
        public static bool IsDebug = false;
        private static String PlainInput = @"





4
M M M M





";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0