結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー aaa aa
提出日時 2025-11-11 16:01:06
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 1,003 bytes
コンパイル時間 7,571 ms
コンパイル使用メモリ 167,496 KB
実行使用メモリ 188,576 KB
最終ジャッジ日時 2025-11-11 16:01:20
合計ジャッジ時間 12,368 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 16 RE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (98 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
public class Program
{
    public static void Main()
    {
        int num = int.Parse(Console.ReadLine() ?? string.Empty);
        string[] number = (Console.ReadLine() ?? string.Empty).Trim().Split(' ');

        int[] numnum = new int [num];
        for (int i = 0; i < num; i++)
        {
            numnum[i] = int.Parse(number[i]);
        }

        for (int i = 0;i < numnum.Length-1; i++)
        {
            for (int j = 0; j < numnum.Length - 1; j++)
            {
                if (numnum[j] > numnum[j + 1])
                {
                    int box = numnum[j];

                    numnum[j] = numnum[j + 1];
                    numnum[j + 1] = box;
                }
            }
        }

        if(num % 2 != 0)
        {
            Console.WriteLine("{0}", numnum[num % 2]);
        }
        else
        {
            double ans = numnum[num / 2] + numnum[(num / 2) - 1];
            ans /= 2;
            Console.WriteLine("{0}", ans);
        }

    }
}
0