結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー a2011404
提出日時 2017-03-03 15:29:47
言語 C90
(gcc 12.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 502 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 380 ms
コンパイル使用メモリ 22,344 KB
最終ジャッジ日時 2026-01-17 07:55:33
合計ジャッジ時間 1,121 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function ‘main’:
main.c:36:1: error: C++ style comments are not allowed in ISO C90
   36 | //for(i=0;i<n;i++){             /*並び替え確認*/
      | ^
main.c:36:1: note: (this will be reported only once per input file)
main.c:29:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 | scanf("%d",&n);
      | ^~~~~~~~~~~~~~
main.c:32:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |         scanf("%d",&x[i]);
      |         ^~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include<stdio.h>
#include<stdlib.h>




int sortfnc(const void *a,const void *b){

	if(*(int*)a == *(int*)b){
	return 0;
	}

	if(*(int*)a < *(int*)b){
	return -1;
	}

	return 1;

}



int main(void)
{

int n,i,x[1000];
double AVE=0;

scanf("%d",&n);

for(i=0;i<n;i++){
	scanf("%d",&x[i]);
}
	qsort(x, n, sizeof(int), sortfnc);

//for(i=0;i<n;i++){		/*並び替え確認*/
//	printf("%d\n",x[i]);
//}


if(n%2 != 0)	AVE=x[(n-1)/2];
else		AVE=(x[n/2-1]+x[n/2])/2.0;

printf("%.1f\n",AVE);



return 0;
}
0