結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2020-02-13 22:21:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 573 bytes |
コンパイル時間 | 388 ms |
コンパイル使用メモリ | 46,536 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-06 06:32:35 |
合計ジャッジ時間 | 1,515 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <algorithm>using namespace std;int main(){int answer;int n;scanf("%d", &n);int array[n];for (int i = 0; i < n; i++){int a;scanf("%d", &a);array[i] = a;}sort(array, array + sizeof(array) / sizeof(array[0]));if (n % 2 == 0){int index1 = n / 2 - 1;int index2 = index1 + 1;printf("%.1f\n", (array[index1] + array[index2]) / 2.0);}else{printf("%d\n", array[n / 2]);}}