FreshLittleLemon @ 2023-08-14 11:48:01
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,max=0,min=10,sum=0;
double ave;
int* a=(int *)malloc(n*sizeof(int));
scanf("%d",&n);
for (i=0;i<n;i++) {
scanf("%d",&a[i]);
if (a[i]>max) {
max=a[i];
}
if (a[i]<min) {
min=a[i];
}
sum+=a[i];
}
ave=1.0*(sum-max-min)/(n-2);
printf("%.2lf",ave);
}
这到底是为什么嘞
by wangsitan @ 2023-08-20 10:33:04
#include <bits/stdc++.h>
using namespace std;
int n,d;
int a[1005];
int main()
{
float m;
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++)
{
m=m+a[i];
}
m=m/(n-2);
cout<<fixed<<setprecision(2)<<m;
return 0;
}
by Qiaozi_Tyc @ 2023-08-22 14:00:46
qp
by all___right @ 2023-08-24 20:19:28
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,ma,mi;
double b=0;//双精度
cin>>n;
for(int i=1;i<=n;i++){
cin>>a;
b=b+a;//统计所有分
if(i==1){
ma=a;
mi=a;//在初始时min,max都为a
}
if(ma<a){
ma=a;//当max小于a时max=a
}
if(mi>a){
mi=a;//当min大于a时min=a
}
}
b=b-ma-mi;//在循环外改掉最大分和最小分
printf("%.2f",b/(n-2));//cout太长改用printf,这里把最大最小打分者从n中去掉
return 0;
}
@FreshLittleLemon