結果

問題 No.275 中央値を求めよ
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-13 19:00:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 80 ms / 1,000 ms
コード長 1,497 bytes
コンパイル時間 2,850 ms
コンパイル使用メモリ 108,204 KB
実行使用メモリ 24,100 KB
最終ジャッジ日時 2023-09-07 04:44:02
合計ジャッジ時間 7,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
21,920 KB
testcase_01 AC 69 ms
21,896 KB
testcase_02 AC 68 ms
21,828 KB
testcase_03 AC 64 ms
23,816 KB
testcase_04 AC 69 ms
21,828 KB
testcase_05 AC 68 ms
19,792 KB
testcase_06 AC 69 ms
23,888 KB
testcase_07 AC 78 ms
22,068 KB
testcase_08 AC 71 ms
21,988 KB
testcase_09 AC 70 ms
22,036 KB
testcase_10 AC 76 ms
24,000 KB
testcase_11 AC 62 ms
21,796 KB
testcase_12 AC 69 ms
19,792 KB
testcase_13 AC 63 ms
19,764 KB
testcase_14 AC 69 ms
21,936 KB
testcase_15 AC 78 ms
22,024 KB
testcase_16 AC 78 ms
22,104 KB
testcase_17 AC 78 ms
22,188 KB
testcase_18 AC 78 ms
20,128 KB
testcase_19 AC 73 ms
22,012 KB
testcase_20 AC 78 ms
22,036 KB
testcase_21 AC 78 ms
22,080 KB
testcase_22 AC 78 ms
22,148 KB
testcase_23 AC 73 ms
22,060 KB
testcase_24 AC 80 ms
24,100 KB
testcase_25 AC 78 ms
22,172 KB
testcase_26 AC 78 ms
21,956 KB
testcase_27 AC 73 ms
22,056 KB
testcase_28 AC 66 ms
21,752 KB
testcase_29 AC 73 ms
22,060 KB
testcase_30 AC 64 ms
21,700 KB
testcase_31 AC 80 ms
20,132 KB
testcase_32 AC 73 ms
24,088 KB
testcase_33 AC 73 ms
21,976 KB
testcase_34 AC 65 ms
21,784 KB
testcase_35 AC 72 ms
21,980 KB
testcase_36 AC 73 ms
24,008 KB
testcase_37 AC 76 ms
22,068 KB
testcase_38 AC 77 ms
22,036 KB
testcase_39 AC 73 ms
21,956 KB
testcase_40 AC 72 ms
23,968 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 = "Input4";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("5 3 4");
            //4
            //この場合の中央値は4です。
            //4.00のような出力でも良い。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("1 9 8 4");
            //6
            //この場合は(8+4)/2=6です。
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6");
            WillReturn.Add("1 2 3 4 5 6");
            //3.5
            //この場合の答えは小数になります。
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        Array.Sort(AArr);
        int wkLen=AArr.Length;

        if (wkLen % 2 == 0) {
            decimal Answer = AArr[wkLen / 2];
            Answer += AArr[wkLen / 2-1];
            Console.WriteLine(Answer / 2);
        }
        else {
            Console.WriteLine(AArr[wkLen / 2]);
        }
    }
}
0