結果

問題 No.539 インクリメント
ユーザー aketijyuuzouaketijyuuzou
提出日時 2024-10-10 23:48:03
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 3,039 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 108,800 KB
実行使用メモリ 40,412 KB
最終ジャッジ日時 2024-10-10 23:48:06
合計ジャッジ時間 2,235 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
18,560 KB
testcase_01 AC 114 ms
40,412 KB
testcase_02 AC 103 ms
36,748 KB
testcase_03 AC 119 ms
36,752 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;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("yuki2006");
            WillReturn.Add("rng_58");
            WillReturn.Add("sugim48");
            WillReturn.Add("02/29/2016");
            WillReturn.Add("D programming language version 0.99");
            //yuki2007
            //rng_59
            //sugim49
            //02/29/2017
            //D programming language version 0.100
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("7");
            WillReturn.Add("hoge999hoge");
            WillReturn.Add("73-23=49");
            WillReturn.Add("O(n^2 log n)");
            WillReturn.Add("hoge0003871hoge");
            WillReturn.Add("00000000000000000000000");
            WillReturn.Add("-0");
            WillReturn.Add("piyo");
            //hoge1000hoge
            //73-23=50
            //O(n^3 log n)
            //hoge0003872hoge
            //00000000000000000000001
            //-1
            //piyo
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string[] SArr = InputList.Skip(1).ToArray();

        foreach (string EachStr in SArr) {
            var NumLeftList = new List<char>();
            var NumList = new List<char>();
            var NumRightList = new List<char>();

            List<char> CurrList = NumRightList;

            for (int I = EachStr.Length - 1; 0 <= I; I--) {
                if ('0' <= EachStr[I] && EachStr[I] <= '9') {
                    if (CurrList == NumRightList) CurrList = NumList;
                }
                else {
                    if (CurrList == NumList) CurrList = NumLeftList;
                }
                CurrList.Add(EachStr[I]);
            }
            ExecIncrement(NumList);

            NumLeftList.Reverse();
            NumList.Reverse();
            NumRightList.Reverse();

            var wkList = new List<char>();
            wkList.AddRange(NumLeftList);
            wkList.AddRange(NumList);
            wkList.AddRange(NumRightList);

            var sb = new System.Text.StringBuilder();
            wkList.ForEach(X => sb.Append(X));
            Console.WriteLine(sb.ToString());
        }
    }

    //数値をインクリメントして返す
    static void ExecIncrement(List<char> pNumList)
    {
        if (pNumList.Count == 0) return;

        int UB = pNumList.Count - 1;
        pNumList[0]++;

        for (int I = 0; I <= UB; I++) {
            if (pNumList[I] <= '9') break;
            pNumList[I] = '0';

            if (I == UB) pNumList.Add('1');
            else pNumList[I + 1]++;
        }
    }
}

0