結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2017-06-28 11:31:12 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 537 bytes |
コンパイル時間 | 1,495 ms |
コンパイル使用メモリ | 159,704 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 00:33:56 |
合計ジャッジ時間 | 2,456 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
コンパイルメッセージ
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[10000];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;}