Pjcgs @ 2023-02-25 15:27:48
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n,a[1001];
double t=0;
cin>>n;
for(int i=1;i<=n;i++)
a[i]=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a,a+n+1);
for(int i=2;i<=n-1;i++)
t+=a[i];
printf("%.2f",t/(n-2));
return 0;
}
by InversionShadow @ 2023-02-25 15:30:11
《 sort(a,a+n+1);
》
by 幻想繁星 @ 2023-02-25 15:30:12
@Pjcgs sort传参错误
by wangzelin @ 2023-02-25 15:31:07
sort(a+1,a+n+1);
by wangzelin @ 2023-02-25 15:32:11
或者for初始化时改成for(int i=0;i<=n;i++)
by Pjcgs @ 2023-02-25 15:32:32
请问这有什么讲究吗sort?求教
by AC_CSP @ 2023-02-25 15:33:33
@Pjcgs 您要不要看看自己在说什么qwq
by 幻想繁星 @ 2023-02-25 15:34:23
@Pjcgs 建议自行学习,要不然这题建议改为冒泡
by csy_start @ 2023-03-05 14:16:21
@ wangzelin 同意
by fkcufk @ 2023-03-13 19:12:24
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main(){
int n;
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i];
sort(a+1,a+n+1);
a[1]=a[n]=0;
int sum=0;
for(int i=1;i<=n;i++) sum+=a[i];
printf("%.2f",1.0*sum/(n-2));
return 0;
}
by _Adolf_Hitler_ @ 2023-06-03 17:44:05
sort(a,a+1+n);
既然
的下标是从