結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2019-12-07 23:18:10 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 738 bytes |
コンパイル時間 | 1,434 ms |
コンパイル使用メモリ | 29,696 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-26 15:20:58 |
合計ジャッジ時間 | 1,480 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <stdio.h>int sort(int n, int str[]);int calMedian(int n, int str[]);int main(void){int n;int str[1000];scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%d", &(str[i]));//printf("%d %d %d", str[0],str[1],str[2]); testsort(n, str);calMedian(n, str);return 0;}int sort(int n, int str[]){int i,j;int a;for (i = 0; i <= n - 1; i++) {for (j = 1; j <= n - i - 1; j++) {if (str[i] > str[i + j]) {a = str[i];str[i] = str[i + j];str[i + j] = a;}}}return 0;}int calMedian(int n, int str[]){double a;if (n % 2 == 0) {a = (str[n / 2 -1] + str[n / 2 ]) / 2.0;printf("%.1f\n", a);}else {a = str[(n+1)/2 -1];printf("%.1f\n", a);}return 0;}