結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー moshiya02
提出日時 2018-03-15 20:00:36
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 542 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 500 ms
コンパイル使用メモリ 71,408 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-28 00:55:08
合計ジャッジ時間 2,157 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:37:11:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:232:25: warning: 'median' may be used uninitialized [-Wmaybe-uninitialized]
  232 |       { return _M_insert(__f); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:24:10: note: 'median' was declared here
   24 |   double median;
      |          ^~~~~~

ソースコード

diff #
raw source code

#include<iostream>
using namespace std;

int main(){
  int n;
  cin >> n;

  int a[n];
  for(int i=0;i<n;i++)
    cin >> a[i];

  int i, j, tmp;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[i]>a[j]){
	tmp = a[i];
	a[i] = a[j];
	a[j] = tmp;
      }
    }
  }

  int  c1, c2;
  double median;
  for(i=0;i<n-1;i++){
    if(n%2 == 0){
      //EVEN
      c1 = a[ n/2 - 1 ];
      c2 = a[ n/2 ];
      median = (double)(c1 + c2) / 2;
    }else{
      //ODD
      median = a[ n/2 ];
    }
  }

  cout << median << endl;
  
  return 0;
}
0