結果
問題 |
No.275 中央値を求めよ
|
ユーザー |
![]() |
提出日時 | 2018-02-22 23:13:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 530 bytes |
コンパイル時間 | 203 ms |
コンパイル使用メモリ | 25,216 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 00:51:20 |
合計ジャッジ時間 | 1,315 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d",&length); | ~~~~~^~~~~~~~~~~~~~ main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d",&ary[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <cstdlib> int compare_int(const void *a, const void *b) { return *(int*)a - *(int*)b; } void FindMedian(int size, int *vector) { if (size%2) { printf("%f\n",(float)vector[(size-1)/2]); } else { printf("%f\n",( (float)( vector[size/2]+vector[size/2-1] ) / 2 ) ); } } int main(void) { int length; int ary[1000]; scanf("%d",&length); for(int i=0;i<length;i++){ scanf("%d",&ary[i]); } qsort(ary, length, sizeof(int), compare_int); FindMedian(length, ary); return 0; }