結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2018-03-27 19:10:43 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 452 bytes |
コンパイル時間 | 565 ms |
コンパイル使用メモリ | 54,876 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 01:04:32 |
合計ジャッジ時間 | 1,754 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include<iostream>using namespace std;int main(){int n,temp;cin >> n;int a[n];for(int i=0; i<n; i++){cin >> a[i];}for(int i=0; i<n-1; i++){for(int j=i+1; j<n; j++){if(a[i] < a[j]){temp = a[i];a[i] = a[j];a[j] = temp;}}}double median;if(n%2 == 0){median = (a[n/2-1] + a[n/2])/2.0;}else{median = a[n/2];}cout << median << endl;return 0;}