結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2018-06-22 15:43:57 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 566 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 23,552 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 01:42:20 |
合計ジャッジ時間 | 1,396 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:19:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d", &A[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include<stdio.h>void sort(int *a, int size){int i, j, tmp;for(i = 0 ; i < size-1; i++){for(j = size-1; j > i; j--){if(a[j-1] > a[j]){tmp = a[j-1];a[j-1] = a[j];a[j] = tmp;}}}}int main(void){int i;int N, A[1000];scanf("%d", &N);for(i = 0; i < N; i++){scanf("%d", &A[i]);}sort(A, N);if(N % 2) printf("%d\n", A[N / 2]);else if((A[N / 2 - 1] + A[N / 2]) % 2){printf("%.1lf\n", (double)(A[N / 2 - 1] + A[N / 2 ]) / 2);}else printf("%d\n", (A[N / 2 - 1] + A[N / 2]) / 2);return 0;}