結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-29 22:40:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 629 bytes |
| コンパイル時間 | 577 ms |
| コンパイル使用メモリ | 55,584 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 00:13:02 |
| 合計ジャッジ時間 | 1,789 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:31: warning: ‘locate’ may be used uninitialized in this function [-Wmaybe-uninitialized]
26 | loose[locate] = 1001;
| ~~~~~~~~~~~~~~^~~~~~
ソースコード
#include<iostream>
using namespace std;
int main(){
/*数字の数*/
int number;
cin >> number;
/*ソート前の配列*/
int loose[number];
for(int i=0; i<number; i++){
cin >> loose[i];
}
/*ソート後の配列*/
int low=1001, locate;
int sorted[number];
for(int a=0; a<number; a++){
for(int b=0; b<number; b++){
if(loose[b] < low){
low = loose[b];
locate = b;
}
}
sorted[a] = loose[locate];
loose[locate] = 1001;
low = 1001;
}
/*中央値を表示*/
if(number%2 == 0)
cout << (sorted[(number/2)-1]+sorted[(number/2)]) / 2.0 << endl;
else
cout << sorted[(number/2)] << endl;
}