結果

問題 No.275 中央値を求めよ
ユーザー ooh_23ooh_23
提出日時 2017-06-01 10:28:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 86 ms / 1,000 ms
コード長 797 bytes
コンパイル時間 2,564 ms
コンパイル使用メモリ 102,492 KB
実行使用メモリ 27,988 KB
最終ジャッジ日時 2023-09-07 06:04:58
合計ジャッジ時間 7,110 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
23,848 KB
testcase_01 AC 71 ms
23,836 KB
testcase_02 AC 72 ms
23,644 KB
testcase_03 AC 72 ms
25,728 KB
testcase_04 AC 71 ms
23,728 KB
testcase_05 AC 71 ms
23,580 KB
testcase_06 AC 72 ms
23,976 KB
testcase_07 AC 80 ms
24,000 KB
testcase_08 AC 79 ms
23,976 KB
testcase_09 AC 78 ms
23,832 KB
testcase_10 AC 78 ms
23,944 KB
testcase_11 AC 70 ms
25,692 KB
testcase_12 AC 68 ms
23,716 KB
testcase_13 AC 67 ms
21,836 KB
testcase_14 AC 68 ms
21,712 KB
testcase_15 AC 80 ms
23,908 KB
testcase_16 AC 81 ms
25,992 KB
testcase_17 AC 81 ms
24,048 KB
testcase_18 AC 80 ms
23,856 KB
testcase_19 AC 81 ms
27,988 KB
testcase_20 AC 80 ms
21,940 KB
testcase_21 AC 79 ms
25,996 KB
testcase_22 AC 80 ms
23,864 KB
testcase_23 AC 79 ms
24,080 KB
testcase_24 AC 80 ms
26,016 KB
testcase_25 AC 80 ms
23,972 KB
testcase_26 AC 80 ms
23,952 KB
testcase_27 AC 81 ms
22,044 KB
testcase_28 AC 72 ms
23,728 KB
testcase_29 AC 86 ms
26,064 KB
testcase_30 AC 70 ms
21,728 KB
testcase_31 AC 82 ms
25,952 KB
testcase_32 AC 80 ms
26,060 KB
testcase_33 AC 81 ms
23,924 KB
testcase_34 AC 72 ms
25,576 KB
testcase_35 AC 81 ms
24,104 KB
testcase_36 AC 80 ms
23,844 KB
testcase_37 AC 79 ms
23,840 KB
testcase_38 AC 79 ms
21,972 KB
testcase_39 AC 80 ms
24,016 KB
testcase_40 AC 82 ms
25,940 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;
using System.Text;
using System.Threading.Tasks;

namespace lecture
{
    class Program
    {

        static void Main(string[] args)
        {
            int a = 0;
            double result = 0;

            int n = int.Parse(Console.ReadLine());
            double[] data = Console.ReadLine().Trim().Split(' ').Select(x => double.Parse(x)).ToArray();
            Array.Sort(data);
            // 真ん中の計算
            a = n / 2;
            // 中央値の計算
            if (data.Length % 2 == 0)
            {
                result = (data[a-1] + data[a]) / 2;
            }
            else
            {
                result = data[a];
            }
            Console.WriteLine(result);
        }
    }
}
0