結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2017-03-03 15:29:47 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 502 bytes |
コンパイル時間 | 581 ms |
コンパイル使用メモリ | 21,760 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 00:23:45 |
合計ジャッジ時間 | 1,277 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.c: In function ‘main’: 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]); | ^~~~~~~~~~~~~~~~~
ソースコード
#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; }