結果

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

ソースコード

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.0f\n",numberList[n/2]);
		//printf("取得値:%d\n",numberList[n/2]);
	} else {
		printf("%0.0f\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