結果

問題 No.275 中央値を求めよ
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-13 19:00:47
言語 C#
(csc 3.9.0)
結果
AC  
実行時間 70 ms / 1,000 ms
コード長 1,497 bytes
コンパイル時間 2,067 ms
実行使用メモリ 16,268 KB
最終ジャッジ日時 2023-01-22 20:11:02
合計ジャッジ時間 6,367 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
15,984 KB
testcase_01 AC 62 ms
15,868 KB
testcase_02 AC 63 ms
15,964 KB
testcase_03 AC 56 ms
15,788 KB
testcase_04 AC 62 ms
15,784 KB
testcase_05 AC 63 ms
15,884 KB
testcase_06 AC 63 ms
15,996 KB
testcase_07 AC 70 ms
16,108 KB
testcase_08 AC 64 ms
16,136 KB
testcase_09 AC 65 ms
16,004 KB
testcase_10 AC 69 ms
16,060 KB
testcase_11 AC 55 ms
15,960 KB
testcase_12 AC 62 ms
15,928 KB
testcase_13 AC 56 ms
15,920 KB
testcase_14 AC 63 ms
15,976 KB
testcase_15 AC 70 ms
16,268 KB
testcase_16 AC 70 ms
16,184 KB
testcase_17 AC 70 ms
16,160 KB
testcase_18 AC 70 ms
16,112 KB
testcase_19 AC 65 ms
16,132 KB
testcase_20 AC 70 ms
16,216 KB
testcase_21 AC 70 ms
16,220 KB
testcase_22 AC 70 ms
16,108 KB
testcase_23 AC 65 ms
16,100 KB
testcase_24 AC 70 ms
16,188 KB
testcase_25 AC 70 ms
16,216 KB
testcase_26 AC 66 ms
16,244 KB
testcase_27 AC 64 ms
16,160 KB
testcase_28 AC 58 ms
15,904 KB
testcase_29 AC 65 ms
16,040 KB
testcase_30 AC 57 ms
15,856 KB
testcase_31 AC 70 ms
16,232 KB
testcase_32 AC 63 ms
16,108 KB
testcase_33 AC 65 ms
16,096 KB
testcase_34 AC 57 ms
15,788 KB
testcase_35 AC 64 ms
16,080 KB
testcase_36 AC 65 ms
16,108 KB
testcase_37 AC 68 ms
16,224 KB
testcase_38 AC 70 ms
16,216 KB
testcase_39 AC 64 ms
16,096 KB
testcase_40 AC 65 ms
16,228 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