結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2018-03-17 22:13:07 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 481 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 37,676 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 01:00:13 |
合計ジャッジ時間 | 1,466 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d",&A[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <algorithm> int main(){ //input int N; scanf("%d",&N); int A[1000]; for (int i = 0;i < N;i++){ scanf("%d",&A[i]); } //sort array A std::sort(A,A+N); //calculate median float median; if (N%2 == 0){ int index = N/2-1; median = 0.5*(A[index]+A[index+1]); }else{ int index = (N-1)/2; median = A[index]; } //output printf("%f\n",median); return 0; }