結果

問題 No.275 中央値を求めよ
ユーザー sasa
提出日時 2025-03-03 17:32:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 456 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 28,032 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-03-03 17:32:53
合計ジャッジ時間 1,860 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:25: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘double*’ [-Wformat=]
   10 |                 scanf("%d",&p[i]);
      |                        ~^  ~~~~~
      |                         |  |
      |                         |  double*
      |                         int*
      |                        %le
main.cpp:11:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=]
   11 |                 printf("%d\n",p[i]);
      |                         ~^    ~~~~
      |                          |       |
      |                          int     double
      |                         %f
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d",&num);
      |         ~~~~~^~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%d",&p[i]);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(void){
	int num = 0;
	scanf("%d",&num);
	
	double val[num];
	double *p = val;
	for(int i = 0;i < num;i++){
		scanf("%d",&p[i]);
		printf("%d\n",p[i]);
	}
	double ans = 0;
	double res = num / 2;
	for(int i = 0;i < num;i++){
		if(res == i){
			if(num % 2 == 0){
				ans = (val[i] + val[i - 1]) / 2;
				printf("偶数の場合の合計%lf\n",val[i] + val[i - 1]);
			}else{
				ans = val[i];
			}		
		}
	}
	printf("%lf",ans);
	
}
0