zwb3_1415926 @ 2021-08-24 09:23:10
#include<bits/stdc++.h>
using namespace std;
int main()
{
double e;
int n,c,n1,n2,n3,n4,e1;
cin>>n;
int b[n];
for (n1=0;n1<=n;n1++)
{
cin>>c;
b[n1]=c;
}
for (n2=0;n2<=n;n2++)
{
for (n3=n2+1;n3<=n;n3++)
{
if (b[n2]<b[n3])
{
e1=b[n2];
b[n2]=b[n3];
b[n3]=e1;
}
}
}
for (n4=1;n4<=n-1;n4++)
{
if (n-1==n4)
continue;
e=e+b[n4];
}
printf("%.2f",e/(n-2));
return 0;
}
by wssbi @ 2021-08-24 09:28:37
@zwb3_1415926
???您的数组下标是从0开始的为什么还要循环到n
呢???
for (n1=0;n1<=n;n1++)
{
cin>>c;
b[n1]=c;
}
for (n2=0;n2<=n;n2++)
{
for (n3=n2+1;n3<=n;n3++)
{
if (b[n2]<b[n3])
{
e1=b[n2];
b[n2]=b[n3];
b[n3]=e1;
}
}
}
这一段改成
for (n1=0;n1<n;n1++)
{
cin>>c;
b[n1]=c;
}
for (n2=0;n2<n;n2++)
{
for (n3=n2+1;n3<n;n3++)
{
if (b[n2]<b[n3])
{
e1=b[n2];
b[n2]=b[n3];
b[n3]=e1;
}
}
}
即可AC
by 404Not_Found @ 2021-08-24 09:28:38
你数组开在外面吧,
by SunLegend @ 2021-08-24 09:32:49
找到最大最小值和累加和就行了
by nanzjz1 @ 2021-08-24 09:41:48
数组不能开 const int MAXN=100
中的MAXN
也可以看作是常量;当然也可以通过new
来创建动态数组(但是目前几乎用不上),常见的动态数组是vector。
很好奇为什么你的编译器没报错
by nanzjz1 @ 2021-08-24 09:43:54
是我火星了……这样写居然能过 评测记录
by XiaoX @ 2021-08-24 09:53:08
@nanzjz1 GCC支持这样
by zwb3_1415926 @ 2021-08-24 14:12:23
谢谢大佬指点!!