結果

問題 No.275 中央値を求めよ
ユーザー Yatsuku
提出日時 2015-11-08 22:45:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 554 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 23,552 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 14:11:37
合計ジャッジ時間 1,261 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 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]);
      |                 ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#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;
			}
		}
	}
	for ( k1 = 1; k1 <= a; k1++ ) {
		printf("%.1f ", b[k1]);
	}
	puts("");

	if ( a % 2 == 0 ) {
		c = a;
		printf("%.1f", ((b[c/2] + b[a/2+1]) / 2));
	} else {
		printf("%.1f", b[a/2+1]);
	}
	puts("");

	return 0;

}
0