結果

問題 No.123 カードシャッフル
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-15 09:59:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 2,736 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 105,024 KB
実行使用メモリ 28,936 KB
最終ジャッジ日時 2023-09-25 12:00:57
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,792 KB
testcase_01 AC 62 ms
23,812 KB
testcase_02 AC 63 ms
21,952 KB
testcase_03 AC 64 ms
23,948 KB
testcase_04 AC 64 ms
23,956 KB
testcase_05 AC 63 ms
23,920 KB
testcase_06 AC 63 ms
21,800 KB
testcase_07 AC 63 ms
23,948 KB
testcase_08 AC 62 ms
21,768 KB
testcase_09 AC 61 ms
21,788 KB
testcase_10 AC 91 ms
26,472 KB
testcase_11 AC 100 ms
26,928 KB
testcase_12 AC 107 ms
26,804 KB
testcase_13 AC 107 ms
28,936 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 = "Input5";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("3 1");
            WillReturn.Add("2");
            //2
            //最初に1から3までの3枚のカードが積まれています。上から1,2,3の順です。
            //1回目のシャッフルで上から2番目の2の数字のカードを抜いていちばん上に積みます。
            //よって、いちばん上のカードは2になります。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3 2");
            WillReturn.Add("3 2");
            //1
            //最初に1から3までの3枚のカードが積まれています。上から1,2,3の順です。
            //1回目のシャッフルで上から3番目の3の数字のカードを抜いていちばん上に積みます。
            //カードは上から順に3,1,2の順で積まれています。
            //2回目のシャッフルで上から2番目の1の数字のカードを抜いていちばん上に積みます。
            //よって、いちばん上のカードは1になります。
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("4 4");
            WillReturn.Add("1 1 1 1");
            //1
            //最初に1から4までの4枚のカードが積まれています。上から1,2,3,4の順です。
            // 上から1番目のカードを抜いて上に積むシャッフルを4回行います。
            //カードの順番はまったく動きません。よって、いちばん上のカードの数字は1です。
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("10 8");
            WillReturn.Add("6 10 4 2 7 1 4 3");
            //10
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        List<int> NList = Enumerable.Range(1, wkArr[0]).ToList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        Action<int> ShuffleAct = (pInd) =>
        {
            int SaveInt = NList[pInd];
            NList.RemoveAt(pInd);
            NList.Insert(0, SaveInt);
        };

        Array.ForEach(AArr, X => ShuffleAct(X - 1));
        Console.WriteLine(NList[0]);
    }
}
0