結果

問題 No.275 中央値を求めよ
ユーザー Baku_beanpole
提出日時 2016-01-21 14:33:24
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 754 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 22,016 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-21 14:56:22
合計ジャッジ時間 1,219 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:41:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:47:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |                 scanf("%d", &array[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

void QuickSort(int array[], int begin, int end)
{
	int i = begin;
	int j = end;
	int pivot;
	int temp;

	pivot = array[(begin + end) / 2];  

	while(1){
		while(array[i] < pivot ){
			++i; 
		} 
		while(array[j] > pivot){
			--j;
		}

		if(i >= j)break;  

		temp = array[i];
		array[i] = array[j];
		array[j] = temp;
		i++;
		j--;
	}

	if(begin < i - 1){
		QuickSort(array, begin, i - 1);
		}

	if(j + 1 < end){
		QuickSort(array, j + 1, end);
		}
}

int main(){

	int n;
	scanf("%d", &n);

	int array[n];

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

	QuickSort(array, 0, n-1);

	if(n % 2 == 0){
		printf("%f\n", (double)((array[n/2 - 1] + array[n/2]) / 2.0));
	}else{
		printf("%d\n", array[1]);
	}

	return 0;

}
0