Kmeow @ 2024-03-25 20:39:16
#include <bits/stdc++.h>
using namespace std;
double n[1010];
double maxn=0,minn=11,cnt,sum;
double score;
int main(){
int n1;
cin>>n1;
for(int i=1;i<=n1;i++)
{
cin>>n[i];
if(n[i]>=maxn) maxn=n[i];
if(n[i]<=minn) minn=n[i];
}
for(int i=1;i<=n1;i++)
if(n[i]==maxn||n[i]==minn) n[i]==0;
for(int i=1;i<=n1;i++)
{
if(n[i]!=0)
{
cnt++;
sum+=n[i];
}
else
continue;
}
score=sum/cnt;
cout<<fixed << setprecision(2)<<score<<endl;
return 0;
}
by Lg2307 @ 2024-03-25 20:48:00
修改后的代码如下:
#include <bits/stdc++.h>
using namespace std;
double n[1010];
double maxn=0,minn=11,cnt,sum = 0;
double score;
int main(){
int n1;
cin>>n1;
for(int i=1;i<=n1;i++)
{
cin>>n[i];
/*if(n[i]>=maxn) maxn=n[i];
if(n[i]<=minn) minn=n[i];*/
maxn = max(maxn,n[i]);
minn = min(minn,n[i]);
sum += n[i];
}
/*for(int i=1;i<=n1;i++)
if(n[i]==maxn||n[i]==minn) n[i]==0;
for(int i=1;i<=n1;i++)
{
if(n[i]!=0)
{
cnt++;
sum+=n[i];
}
else
continue;
}
score=sum/cnt;
*/
score = (sum - maxn - minn) / (n1 - 2);
cout<<fixed << setprecision(2)<<score<<endl;
return 0;
}
亲测能过。
by Lg2307 @ 2024-03-25 20:48:28
@Kmeow
by tanzexiaodezhonghao @ 2024-03-25 20:58:16
你中间那些是什么???看看我的代码吧……(码风有点烂,不要在意)
#include<bits/stdc++.h>
using namespace std;
double ans=0;
int main(){
int a[1001]={};
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
ans+=a[i];
}
sort(a+1,a+n+1);
ans-=a[n];
ans-=a[1];
printf("%.2lf",ans/(n-2));
return 0;
}
by Lg2307 @ 2024-03-25 21:01:49
我这代码是没学排序之前写的
by anyiming @ 2024-05-22 23:10:08
@Lg2307 @zhouxi2022HZO 这道题也可以不用排序
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int a[n];
cin >> a[0];
int maxi=0,mini=0;
for (int i=1; i<n; i++){
cin >> a[i];
if (a[i] > a[maxi]){
maxi = i;
}else if (a[i] < a[mini]){
mini = i;
}
}
a[mini] = a[maxi] = 0;
double c=0;
for (int i=0; i<n; i++){
c += a[i];
}
cout << fixed << setprecision(2) << c / (n-2);
return 0;
}