FC995 @ 2024-12-24 10:47:58
#include <stdio.h>
#include <math.h>
int main(){
int n;
scanf("%d", &n);
float a[n];
float sum=0.00;
float difference=0.00;
if(n>2 && n<=300){
for(int i=0;i<n;i++){
scanf("%f", &a[i]);
}//写一个 循环输入
float max=a[0];
float min=a[0];
for(int i=0;i<n;i++){
max=(a[i]>=max)?a[i]:max;
min=(a[i]<=min)?a[i]:min;
sum=sum+a[i];
}//找出最大值和最小值
float current_sum=sum-max-min;
//去除最大值和最小值
float average=current_sum/(n-2);
//算出平均值
//printf("%.2f", average);
for(int i=0;i<n;i++){
if(a[i]!=max&&a[i]!=min){
float temp=difference;
//想用temp储存上一次的difference的值 便于比较
difference=abs(a[i]-average);
//在有效数字内 算出他们和平均值差值
if(temp>difference){
difference=temp;
}else if(temp<difference){
return 1;
}else{
difference=0.00;
}
//新的difference和上一个的作比较
}
printf("%.2f %.2f",average, difference);
//按照题目要求输出结果
}
}
return 0;
}
by PengRuiXuan @ 2024-12-24 10:50:16
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x,y;
double a[301],min,max,sum,ave,diff=0;
cin>>n;
cin>>a[0];
min=a[0];
max=a[0];
sum=a[0];
for(int i=1;i<n;i++){
cin>>a[i];
if(a[i]>=max){
max=a[i];
x=i;
}
else if(a[i]<=min){
min=a[i];
y=i;
}
sum=sum+a[i];
}
ave=(sum-max-min)/(n-2);
for(int i=0;i<n;i++){
if(i!=x&&i!=y)
if(fabs(a[i]-ave)>diff)
diff=fabs(a[i]-ave);
}
cout<<setprecision(2)<<fixed<<ave<<" ";
cout<<setprecision(2)<<fixed<<diff;
return 0;
}
by Diary_Of_Young @ 2024-12-25 17:02:57
#include<bits/stdc++.h>
using namespace std;
double a[101001] , sum , cnt;
int n;
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i] ;
sort(a + 1 , a + n + 1);
for(int i = 2 ; i < n ; i ++) sum += a[i];
sum = 1.0 * sum / (n - 2);
for(int i = 2 ; i < n ; i ++) cnt = max(cnt , fabs(sum - 1.0 * a[i]));
printf("%.2lf %.2lf " , sum , cnt);
return 0;
}