两种方法。
```//#include<bits/stdc++.h>
//using namespace std;
//double zgf=-1e9;
//int n,m,a;
//int main(){
// cin>>n>>m;
// for(int i=1;i<=n;i++){
// double sum=0,maxi=-1e9,mini=1e9;
// for(int j=1;j<=m;j++){
// cin>>a;
// sum+=a;
// if(a>maxi) maxi=a;
// if(a<mini) mini=a;
// }
// sum=sum-maxi-mini;
// double pj=sum/(m-2);
// if(pj>zgf) zgf=pj;
// }
// cout<<fixed<<setprecision(2)<<zgf;
// return 0;
//}
#include<bits/stdc++.h>
using namespace std;
double pj(int n,int m){
double sum=0,maxi=-1e9,mini=1e9,a;
for(int i=1;i<=m;i++){
cin>>a;
sum+=a;
if(a>maxi) maxi=a;
if(a<mini) mini=a;
}
return (sum-maxi-mini)/(m-2);
}
int n,m;
double zgf=-1e9;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
double fs=pj(i,m);
if(fs>zgf) zgf=fs;
}
cout<<fixed<<setprecision(2)<<zgf;
return 0;
}
```
by kkksc_tbh @ 2024-10-04 22:02:09
@[LLLLLLsy](/user/1443016) 因为你`int`用`%.2lf`输出呀,包包。
by litangzheng @ 2024-10-04 22:02:17
改成
```
printf("%.2lf",x*1.0/(m-2));//就不会是0了
```
但你写法有问题,参考我的
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
double MAX=INT_MIN;
cin>>n>>m;
for(int i=1;i<=n;i++){
double tmp[10001],sum=0;
for(int j=1;j<=m;j++){
cin>>tmp[j];
sum+=tmp[j];
}
sort(tmp+1,tmp+m+1);
sum=sum-tmp[1]-tmp[m];
sum/=(m-2);
if(sum>MAX){
MAX=sum;
}
}
printf("%.2lf",MAX);
return 0;
}
by Zebraj @ 2024-10-04 22:06:32
求关
by Zebraj @ 2024-10-04 22:07:03
已关,谢谢。
by LLLLLLsy @ 2024-10-05 17:35:31
int改double
by daishuohua @ 2024-10-06 10:08:19
@[LLLLLLsy](/user/1443016)
```cpp
@[daishuohua](/user/872197)
```cpp
#include<iostream>
#include<cmath>
int a[21],n,m;
using namespace std;
double pjz()
{
double z=0;
int maxn=0,minn=11;
for(int i=1;i<=m;i++)
{
int f;
cin>>f;
z+=f;
maxn=max(f,maxn);
minn=min(f,minn);
}
z-=maxn;
z-=minn;
return z;
}
int main()
{
double maxa=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
maxa=max(pjz(),maxa);
}
printf("%.2lf",(double)maxa/(m-2));
return 0;
}
```
```
by guoyanwei120223 @ 2024-10-06 15:21:54
```
#include<iostream>
using namespace std;
int a[30],n,m;
int sum=0,maxx=0,minn=10;
int x=0;
void stat(int a[],int &m){
sum=0,maxx=0,minn=10;
for(int j=0;j<m;j++){
if(maxx<a[j])maxx=a[j];
if(minn>a[j])minn=a[j];
sum+=a[j];
}
sum-=minn;
sum-=maxx;
if(x<sum)x=sum;
}
int main( )
{
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
cin>>a[j];
stat(a,m);
}
printf("%.2lf",(double)x/(m-2));
}
```
@[LLLLLLsy](/user/1443016)
by sunjunyi1017 @ 2024-10-06 15:38:19