結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2018-11-22 17:23:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 616 bytes |
コンパイル時間 | 406 ms |
コンパイル使用メモリ | 54,796 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 02:00:45 |
合計ジャッジ時間 | 1,604 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <iostream> #include <string> #define N 1000 using namespace std; void sort(int n, int a[]) { int i, j, tmp; for (i=0; i<=n-2; i++) { for (j=i+1; j<n; j++) { if (a[i] > a[j]) { tmp = a[i]; a[i] = a[j]; a[j] = tmp; } } } } int main() { int i, n, arr[N], j; cin >> n; for (i=0; i<n; i++) cin >> arr[i]; sort(n, arr); if (n % 2 == 0) { j = n / 2; cout << (double)(arr[j-1] + arr[j]) / 2.0 << endl; } else { j = n / 2; cout << arr[j]; } return 0; }