#include <stdio.h>
#include <math.h>
int main(){
int N, M, cnt, avg;
double s1, s2, min, max, num;
scanf("%d %d", &N, &M);
for(int i = 0; i < N; i++){
scanf("%lf", &s1);
s2 = 0, min = M, max = 0, cnt = 0;
for(int j = 0; j < N-1; j++){
scanf("%lf", &num);
if(num >=0 && num <= M){
cnt++;
s2 += num;
if(num > max) max = num;
if(num < min) min = num;
}
}
s2 = (s2 - min - max) / (cnt - 2);
avg = round( (s1 + s2) / 2 );
printf("%d\n",avg);
}
return 0;
}
对于实现四舍五入,
- round 函数,但是不能直接用在printf中,输出为0,
- (int) (a + 0.5)
int x = (int)(3.78 + 0.5);
int y = round(3.7846);
printf("%d %d",x, y);