結果

問題 No.275 中央値を求めよ
ユーザー toto
提出日時 2025-03-26 16:39:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 474 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 27,776 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-26 16:39:09
合計ジャッジ時間 2,049 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 28 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d",&val);
      |         ~~~~~^~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%d",&arr[i]);
      |                 ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	// 配列の要素数
	int val = 0;
	scanf("%d",&val);
	// 配列の要素
	int arr[val];
	for(int i = 0;i < val;i ++){
		scanf("%d",&arr[i]);
	}
	// ソート
	for(int i = 0;i < val;i ++){
		for(int j = 0;j < val;j ++){
			if(arr[i] < arr[j]){
				int tmp = arr[i];
				arr[i] = arr[j];
				arr[j] = tmp;
			}
		}
	}
	
	if(val % 2 == 0){
		printf("%d",(arr[val / 2] + arr[(val - 1) / 2]) / 2);
		
	}else{
		printf("%d",arr[val / 2]);
	}
	
}
0