結果
問題 |
No.275 中央値を求めよ
|
ユーザー |
![]() |
提出日時 | 2016-01-21 14:31:28 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 742 bytes |
コンパイル時間 | 229 ms |
コンパイル使用メモリ | 21,120 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-21 14:56:21 |
合計ジャッジ時間 | 1,346 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 11 WA * 27 |
コンパイルメッセージ
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]); | ^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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("%d\n", (array[n/2 - 1] + array[n/2]) / 2); }else{ printf("%d\n", array[1]); } return 0; }