結果

問題 No.52 よくある文字列の問題
ユーザー 明智重蔵明智重蔵
提出日時 2015-10-31 21:17:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,942 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 111,600 KB
実行使用メモリ 25,856 KB
最終ジャッジ日時 2023-10-22 04:01:16
合計ジャッジ時間 1,847 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,856 KB
testcase_01 AC 29 ms
25,848 KB
testcase_02 AC 29 ms
25,848 KB
testcase_03 AC 28 ms
25,848 KB
testcase_04 AC 29 ms
25,856 KB
testcase_05 AC 30 ms
25,856 KB
testcase_06 AC 30 ms
25,856 KB
testcase_07 AC 30 ms
25,856 KB
testcase_08 AC 29 ms
25,856 KB
testcase_09 AC 28 ms
25,848 KB
testcase_10 AC 29 ms
25,856 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;

class Program
{
    static string InputPattern = "InputX";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("abc");
            //4
            //abc、acb、cab、cbaの4通りがある
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("aab");
            //3
            //aab、aba、baaの3通りがある
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("aaaaaaaaaa");
            //1
            //どのようにしてもaaaaaaaaaaにしかならない
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct JyoutaiDef
    {
        internal string CurrStr;
        internal string CreateStr;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.CurrStr = S;
        WillPush.CreateStr = "";
        stk.Push(WillPush);

        var CreateStrSet = new HashSet<string>();

        while (stk.Count > 0) {
            JyoutaiDef Popped = stk.Pop();

            //クリア判定
            if (Popped.CurrStr == "") {
                CreateStrSet.Add(Popped.CreateStr);
                continue;
            }

            Action<int> PushSyori = pRemoveInd =>
            {
                WillPush.CurrStr = Popped.CurrStr.Remove(pRemoveInd, 1);
                WillPush.CreateStr = Popped.CreateStr + Popped.CurrStr[pRemoveInd];
                stk.Push(WillPush);
            };

            PushSyori(0);
            PushSyori(Popped.CurrStr.Length - 1);
        }
        Console.WriteLine(CreateStrSet.Count);
    }
}
0