結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2025-03-03 17:52:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 551 bytes |
コンパイル時間 | 342 ms |
コンパイル使用メモリ | 28,160 KB |
実行使用メモリ | 8,608 KB |
最終ジャッジ日時 | 2025-03-03 17:52:04 |
合計ジャッジ時間 | 2,123 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: 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("%lf",&p[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#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("%lf",&p[i]); } // 数値のソート(降順) for(int i = 0;i < num;i++){ for(int j = 0;j < num;j++){ if (p[i] < p[j]) { int x = p[j]; p[j] = p[i]; p[i] = x; } } } double ans = 0; int res = num / 2; for(int i = 0;i < num;i++){ if(res == i){ if(num % 2 == 0){ ans = (val[i] + val[i - 1]) / 2; }else{ ans = val[i]; } } } printf("%g",ans); }