結果

問題 No.275 中央値を求めよ
ユーザー Takuya ItoTakuya Ito
提出日時 2022-12-10 13:29:06
言語 TypeScript
(4.6.2)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 8,201 ms
使用メモリ 38,004 KB
最終ジャッジ日時 2022-12-10 13:29:20
合計ジャッジ時間 11,138 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 82 ms
35,948 KB
testcase_01 AC 67 ms
35,996 KB
testcase_02 AC 65 ms
35,980 KB
testcase_03 WA -
testcase_04 AC 60 ms
35,868 KB
testcase_05 AC 69 ms
35,960 KB
testcase_06 AC 63 ms
35,712 KB
testcase_07 AC 57 ms
35,732 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 67 ms
35,816 KB
testcase_11 WA -
testcase_12 AC 65 ms
35,640 KB
testcase_13 WA -
testcase_14 AC 69 ms
35,704 KB
testcase_15 AC 77 ms
36,148 KB
testcase_16 AC 70 ms
35,736 KB
testcase_17 AC 67 ms
35,964 KB
testcase_18 AC 64 ms
36,052 KB
testcase_19 WA -
testcase_20 AC 69 ms
35,700 KB
testcase_21 AC 65 ms
36,024 KB
testcase_22 AC 70 ms
36,088 KB
testcase_23 WA -
testcase_24 AC 67 ms
36,044 KB
testcase_25 AC 69 ms
35,984 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 67 ms
35,728 KB
testcase_30 AC 56 ms
35,960 KB
testcase_31 AC 75 ms
35,720 KB
testcase_32 AC 69 ms
35,652 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 65 ms
35,692 KB
testcase_38 AC 63 ms
35,668 KB
testcase_39 WA -
testcase_40 AC 72 ms
35,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input: string): void {
  // 入力(2行)を受け取り、扱いやすいように処理
  const inputArr = input.split('\n');
  const numCount = parseInt(inputArr[0], 10);
  const nums = inputArr[1].split(' ')
                          .map(str => parseInt(str, 10))
                          .sort((a, b) => a - b);

  // 数値の数が偶数なら、中央に近い2つの値(length/2 番目とその1つ後ろ)の平均
  //         奇数なら、中央値の切り上げ 番目の値
  let median = 0;
  if (numCount % 2 == 0) {
    median = (nums[(numCount / 2) - 1] + nums[numCount / 2]) / 2
  } else {
    median = nums[Math.ceil(numCount / 2)];
  }

  // 少数第一位までにする(10倍した数で四捨五入して、それを1/10して少数桁を1つだけ作る)
  console.log(Math.round(median * 10) / 10);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0