結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2015-09-17 15:07:43 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 459 bytes |
コンパイル時間 | 230 ms |
コンパイル使用メモリ | 22,144 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-19 06:52:28 |
合計ジャッジ時間 | 1,153 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 21 WA * 17 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:26:28: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=] 26 | printf("%.1f", a[n / 2]); | ~~~^ ~~~~~~~~ | | | | | int | double | %.1d main.c:6:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d", &n); | ^~~~~~~~~~~~~~~ main.c:8:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%d", &a[i]); | ^~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int main(void) { int a[1001], tmp; int i, j, n; scanf("%d", &n); for(i = 0;i < n;i++){ scanf("%d", &a[i]); } for(i = 0;i < n - 1;i++){ for(j = i + 1;j < n;j++){ if(a[j] < a[i]){ tmp = a[j]; a[j] = a[i]; a[i] = tmp; } } } /* for(i = 0;i < n;i++){ printf("%d ", a[i]); } */ if(n % 2 == 1){ printf("%.1f", a[n / 2]); } else{ printf("%.1f", (a[n / 2 - 1] + a[n / 2]) / 2.0); } return 0; }