結果

問題 No.275 中央値を求めよ
ユーザー Maeda
提出日時 2025-03-03 15:42:19
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,037 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 27,008 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-03-03 15:42:21
合計ジャッジ時間 1,850 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 3 WA * 25 RE * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:30:30: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=]
   30 |                 printf("%0.01f\n",numberList[n/2]);
      |                         ~~~~~^    ~~~~~~~~~~~~~~~
      |                              |              |
      |                              double         int
      |                         %0.01d
main.c:33:30: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=]
   33 |                 printf("%0.01f\n",(numberList[n/2] + numberList[n/2-1]) /2);
      |                         ~~~~~^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              |                                          |
      |                              double                                     int
      |                         %0.01d

ソースコード

diff #

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

void main(void){
	int n = 0;
	int inputN = scanf("%d\n",&n);
	if(inputN == 2){
		printf("nの入力ミス\n");
	}
	double median = 0;
	int *numberList = (int *)malloc((size_t)n * sizeof(int));
	for(int i = 0;i < n;i++){
		int inputSum = scanf("%d",&numberList[i]);
		if(inputSum == 2){
			printf("Sumの入力ミス\n");
		}
	}
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			if(numberList[i] > numberList[j]){
				int num = numberList[i];
				numberList[i] = numberList[j];
				numberList[j] = num;
			}
		}
	}
	if(n%2 != 0){
		median = numberList[n/2];
		printf("%0.01f\n",numberList[n/2]);
		//printf("取得値:%d\n",numberList[n/2]);
	} else {
		printf("%0.01f\n",(numberList[n/2] + numberList[n/2-1]) /2);
		//median = (numberList[n/2] + numberList[n/2-1]) /2;
		//printf("取得値:%dと%d\n",numberList[n/2],numberList[n/2-1]);
		//printf("取得値合計:%d\n",numberList[n/2]+numberList[n/2-1]);
	}
	free(numberList);
	//printf("%0.1f\n",median);
}
0