結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2017-10-21 17:14:58 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 824 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 23,808 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 00:42:22 |
合計ジャッジ時間 | 1,234 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%f", &in[itr]); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>void sort(float *src, int size) {int i = 0;int j = 0;int tmp = 0;float *dst;dst = src;for (i = 0; i < size - 1; i++) {for(j = i; j < size - 1; j++) {if (*(dst + i) > *(src + j+1)){tmp = *(dst + j + 1);*(dst + j + 1) = *(dst + i);*(dst + i) = tmp;}}}src = dst;}float getMedian(float *src, int size) {if (size % 2 == 0) {return (*(src + (size - 1)/2) + *(src + (size)/2)) / 2;}return *(src + size/2);}int main(void) {unsigned int N = 0;scanf("%d", &N);float in[1000] = {};unsigned int itr = 0;for (itr = 0;itr < N; itr++) {scanf("%f", &in[itr]);}sort(in, N);printf("%.1f\n", getMedian(in, N));return 0;}