不对,有神奇的错误没调出来
by xionghaoran123 @ 2024-10-30 20:16:12
怀疑人生中。。。
建议重构
by xionghaoran123 @ 2024-10-30 20:19:36
@[Hello___HHH](/user/749465) 经过激烈的讨论,我发现,你删去了最大值后最小值会变为零,导致神奇错误,并且你的答案数组应为double类型
by xionghaoran123 @ 2024-10-30 20:39:17
@[Hello___HHH](/user/749465) 附AC代码
```cpp
#include <bits/stdc++.h>
using namespace std;
int stu[101][21], n, m;
double pinjunn[101];
template<typename T> T maxa(T a[], int b) {
T maxn = -327;
for(int i = 0; i < b; ++i) {
if (a[i] > maxn) {
maxn = a[i];
}
}
return maxn;
}
int mina(int a[], int b) {
int minn = 327;
for(int i = 0; i < b; ++i) {
if (a[i] < minn) {
minn = a[i];
}
}
return minn;
}
double pinjun(int a[], int b) {
int rec=0;
for (int i = 0; i < b; ++i) {
if (a[i]==maxa(a, b)) {
rec=i;
break;
}
}
for (int i=b-1;i>=0;--i) {
if (a[i]==mina(a, b)) {
a[i]=0;
break;
}
}
a[rec]=0;
int ans=0;
for(int i=0;i<b;++i) {
ans+=a[i];
}
return 1.0*ans/(b-2);
}
int main() {
cin>>n>>m;
for(int i=0;i<n;++i) {
for(int j=0;j<m;++j) {
cin>>stu[i][j];
}
}
for (int i=0;i<n;++i) {
pinjunn[i]=pinjun(stu[i],m);
}
// for(int i=0;i<=n-1;i++) printf("%.2lf\n",pinjunn[i]);
// for(int i=0;i<=m-1;i++) printf("%d\n",stu[3][i]);
printf("%.2lf", maxa(pinjunn, n));
return 0;
}
```
by xionghaoran123 @ 2024-10-30 20:41:19