結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-08 23:17:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 482 bytes |
| コンパイル時間 | 360 ms |
| コンパイル使用メモリ | 23,424 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-24 23:29:24 |
| 合計ジャッジ時間 | 1,414 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%lf", &b[k1]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int main(void)
{
int a;
int c;
double tmp;
double b[1000];
int k1, k2;
scanf("%d", &a);
for ( k1 = 1; k1 <= a; k1++ ) {
scanf("%lf", &b[k1]);
}
for ( k1 = 1; k1 < a; k1++ ) {
for ( k2 = 1; k2 < a; k2++ ) {
if ( b[k2] > b[k2+1]) {
tmp = b[k2];
b[k2] = b[k2+1];
b[k2+1] = tmp;
}
}
}
if ( a % 2 == 0 ) {
c = a;
printf("%.1f", (b[c/2] + b[(a/2)+1]) / 2);
} else {
printf("%.1f", b[(a+1)/2]);
}
puts("");
return 0;
}