結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
Elk
|
| 提出日時 | 2018-05-27 20:50:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 577 bytes |
| コンパイル時間 | 153 ms |
| コンパイル使用メモリ | 25,088 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 01:28:48 |
| 合計ジャッジ時間 | 1,327 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int func(const void*, const void*)’:
main.cpp:12:1: warning: control reaches end of non-void function [-Wreturn-type]
12 | }
| ^
main.cpp: In function ‘int main()’:
main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf("%d\n", &N);
| ~~~~~^~~~~~~~~~~~
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%d", &num[i]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
int func(const void *a, const void *b){
if(*(int *)a < *(int *)b){
return -1;
}else if(*(int *)a == *(int *)b){
return 0;
}else if(*(int *)a > *(int *)b){
return 1;
}
}
int main(){
int N, num[1000];
int i;
scanf("%d\n", &N);
for(i = 0; i < N; i++){
scanf("%d", &num[i]);
}
qsort(num, N, sizeof(int), func);
if(N%2 == 0){
printf("%.1f\n", (num[N/2 - 1] + num[N/2])/2.0);
}else if(N%2 == 1){
printf("%d\n", num[N/2]);
}
return 0;
}
Elk