結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-28 11:28:18 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 534 bytes |
| コンパイル時間 | 1,322 ms |
| コンパイル使用メモリ | 160,992 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-04 14:42:59 |
| 合計ジャッジ時間 | 2,324 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 32 |
コンパイルメッセージ
main.cpp: In function ‘void gets(int*, int)’:
main.cpp:7:14: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | fgets(buf, sizeof(buf), stdin);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main(int, char**)’:
main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%d\n", &N);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
void gets(int *a, int n) {
char buf[64];
fgets(buf, sizeof(buf), stdin);
char *b = buf;
for (int i = 0; i < n; i++) {
if (1 != sscanf(b, "%d", a + i)) break;
while (*b != '\0' && !isspace(*b)) b++;
while (*b != '\0' && isspace(*b)) b++;
}
}
int main(int argc, char **argv) {
int N;
scanf("%d\n", &N);
int A[1000];
gets(A, N);
sort(A, A + N);
if (N % 2 == 1) {
printf("%d\n", A[N/2]);
} else {
printf("%.1f\n", (double)(A[N/2-1]+A[N/2])/2.0f);
}
return 0;
}