結果

問題 No.275 中央値を求めよ
ユーザー Yatsuku
提出日時 2015-11-08 23:09:51
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 556 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 21,888 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 14:11:43
合計ジャッジ時間 1,232 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:11:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d", &a);
      |         ^~~~~~~~~~~~~~~
main.c:14:17: warning: ignoring return value of ‘scanf’ 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+1)/2]);
	}
	puts("");

	return 0;

}
0