結果

問題 No.275 中央値を求めよ
ユーザー senkou2000senkou2000
提出日時 2015-09-25 13:51:18
言語 C90
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 841 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 25,800 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 15:02:20
合計ジャッジ時間 3,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 RE -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 1 ms
4,384 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 0 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	int *data,n,i,j,result;
	char *input,input_n[10],*point;
	
	fgets(input_n,sizeof(input_n),stdin);
	sscanf(input_n,"%d",&n);
	
	data=(int *)malloc(sizeof(int)*n);
	input=(char *)malloc(sizeof(char)*n*5+1);
	
	fgets(input,sizeof(char)*n*5+1,stdin);
	
	point=strtok(input," ");
	data[0]=atoi(point);
	
	for(i=1;i<n;i++){
		point=strtok(NULL," ");
		data[i]=atoi(point);
	}
	
	for(i=0;i<n-1;i++){
		for(j=0;j<n-1;j++){
			if(data[j]>data[j+1]){
				int save;
				save=data[j];
				data[j]=data[j+1];
				data[j+1]=save;
			}
			
		}
		
	}
	
	result=n%2;//nが奇数なら1 偶数なら0
	
	if(result==1){
		printf("%d\n",data[n/2]);
	}
	else if(result==0){
		double answer=(data[n/2-1]+data[n/2])/2.0;
		printf("%.1f\n",answer);
	}
	
	
	free(data);
	free(input);
	return 0;
}
0