c语言acm水题不会弄Descriptionfind the median of several integersInputThe first line of input is the number of test cases T(T
来源:学生作业帮助网 编辑:六六作业网 时间:2025/02/08 00:34:38
c语言acm水题不会弄Descriptionfind the median of several integersInputThe first line of input is the number of test cases T(T
c语言acm水题
不会弄
Description
find the median of several integers
Input
The first line of input is the number of test cases T(T
c语言acm水题不会弄Descriptionfind the median of several integersInputThe first line of input is the number of test cases T(T
#include <stdio.h>
void fun(double a[],int m){
int i,j,temp;
for(i=1;i<m;i++)
for (j=0; j<m-i; j++) {
if(a[j]>a[j+1]){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}//冒泡排序
int main(){
int n,m,i;
double a[111];
double ave;
while (~scanf("%d",&n)) {
while (n--) {
scanf("%d",&m);
for(i=0;i<m;i++){
scanf("%lf",&a[i]);
}
fun(a,m);
if(m%2==1){
ave=a[m/2];
}//是奇数
else{
ave=(a[m/2]+a[m/2-1])/2;
}//是偶数
if(int(ave)*1.0==ave)
printf("%d\n",(int)ave);//是整数
else
printf("%.1lf\n",ave);//是小数
}
}
}