hanshuzhili @ 2024-07-30 09:42:06
代码奉上:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int maxx=-1,minn=1e9;
for(int i=0;i<n;i++)
{
cin>>a[i];
maxx=max(maxx,a[i]);
minn=min(minn,a[i]);
}
double s=0.00;
for(int i=0;i<n;i++)
{
if(a[i]!=maxx&&a[i]!=minn)
{
s+=a[i];
}
}
printf("%.2lf",s/(n-2));
return 0;
}
by HFZ20111110 @ 2024-07-30 09:47:19
@hanshuzhili 用sort做
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int n,h;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
h+=a[i];
}
sort(a+1,a+1+n);
h=h-a[1]-a[n];
printf("%.2lf\n",h*1.0/(n-2));
return 0;
}
by HFZ20111110 @ 2024-07-30 09:48:09
@hanshuzhili 如果有用可以给个关注吗?
by zsh_haha @ 2024-07-30 09:49:00
@hanshuzhili
如果有多个评委打出了相同的最高分或最低分,只要减去一个最高分和最低分,你的代码把所有最高分和最低分都减了
by HFZ20111110 @ 2024-07-30 09:49:43
@hanshuzhili 题面说只要去1个最高分和最低分,你这样有多个最高分或最低分就全去了
by zsh_haha @ 2024-07-30 09:51:56
@HFZ20111110
不需要的哦,只要算出和后减一个 maxx
和 minn
最后除以
by HFZ20111110 @ 2024-07-30 09:54:40
@zsh_haha 也可以,但是这道题复杂度不会很高
by hanshuzhili @ 2024-07-31 14:41:20
蟹蟹dalao们,已关