結果
| 問題 |
No.275 中央値を求めよ
|
| ユーザー |
ReERishun
|
| 提出日時 | 2020-04-01 01:03:25 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,170 bytes |
| コンパイル時間 | 281 ms |
| コンパイル使用メモリ | 30,592 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 15:29:46 |
| 合計ジャッジ時間 | 1,629 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 WA * 1 RE * 1 |
ソースコード
#include<stdio.h>
#define PLUS 0;
#define MINUS 1;
int main() {
int dataNum = 0;
int data[1000];
char str='\0';
int mode = PLUS;
// データ数取得
scanf("%d\n", &dataNum);
// 配列初期化
for (int i = 0; i < dataNum + 1; i++)
data[i] = 0;
// 数値に変換
for (int i = 0; str != '\n'; ) {
str = getchar();
if (str == ' ') {
i++;
mode = PLUS;
}
else if (str >= '0' && str <= '9') {
if(mode == 0)
data[i] = data[i] * 10 + (int)str - (int)'0';
else
data[i] = data[i] * 10 - (int)str + (int)'0';
}
else if (str == '-') {
mode = MINUS;
}
}
// ソート
int box = 0;
int flg = 0;
for (int i = 0;; ) {
if (data[i] > data[i + 1]) {
box = data[i];
data[i] = data[i + 1];
data[i + 1] = box;
flg++;
}
i++;
if (i == dataNum - 1) {
if (flg == 0)
break;
else
i = flg = 0;
}
}
// 結果表示
if (dataNum % 2 == 0) {
if((data[dataNum / 2 - 1] + data[dataNum / 2]) % 2!=0)
printf("%d.5", ((data[dataNum / 2 - 1] + data[dataNum / 2]) / 2));
else
printf("%d", ((data[dataNum / 2 - 1] + data[dataNum / 2]) / 2));
}
else
printf("%d", data[dataNum / 2]);
return 0;
}
ReERishun