結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
tekitouk
|
| 提出日時 | 2015-09-05 01:40:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 379 bytes |
| コンパイル時間 | 473 ms |
| コンパイル使用メモリ | 59,368 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-24 23:11:10 |
| 合計ジャッジ時間 | 1,608 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:17:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | scanf(" %d",&A[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
int N;
int A[1000];
scanf("%d",&N);
int i;
for (i = 0; i < N; i++){
scanf(" %d",&A[i]);
}
sort(A,A+N);
if (N % 2 == 1){ printf("%d\n",A[N/2]); }
else{
double x = (double)A[N / 2];
double y = (double)A[(N / 2) - 1];
printf("%.1lf\n",(x+y)/2.0);
}
return 0;
}
tekitouk