結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
Baku_beanpole
|
| 提出日時 | 2016-01-21 14:34:48 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 756 bytes |
| コンパイル時間 | 299 ms |
| コンパイル使用メモリ | 21,760 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 23:40:54 |
| 合計ジャッジ時間 | 1,202 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
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("%f\n", (double)((array[n/2 - 1] + array[n/2]) / 2.0));
}else{
printf("%d\n", array[n/2]);
}
return 0;
}
Baku_beanpole