zxhiding @ 2022-10-08 15:40:54
#include <stdio.h>
int main() {
int n,a[1000],b=0,c=0;
double d = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d",&a[i]);
if (b < a[i]) {
b = a[i];
}
if (c > a[i]) {
c = a[i];
}
d = d + a[i];
}
d = (d - c - b)/ (n - 2);
printf("%.2lf", d);
return 0;
}
by zz_z2Spider @ 2022-10-08 15:47:07
都要用double啊兄弟。
#include<cstdio>
using namespace std;
int main()
{
double min=10000,max,n,a,sum=0,p;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
sum+=a;
if(a>max)
{
max=a;
}
if(a<min)
{
min=a;
}
}sum=sum-max;sum=sum-min; p=sum/(n-2);
printf("%.2lf",p);
return 0;
}
by zxhiding @ 2022-10-08 16:13:11
@kytxxxx_03 我换double了,不对
#include <stdio.h>
int main() {
double n,a[1000],b=0,c=0;
double d = 0;
scanf("%lf", &n);
for (int i = 0; i < n; i++) {
scanf("%lf",&a[i]);
d = d + a[i];
if (b < a[i]) {
b = a[i];
}
if (c > a[i]) {
c = a[i];
}
}
d = d - c;
d = d - b;
double e = d/ (n- 2);
printf("%.2lf", e);
return 0;
}
by zz_z2Spider @ 2022-10-08 16:21:04
@zxhiding 啊,那你看看我代码呢?
by ZHR20100222 @ 2022-10-30 01:06:10
@zxhiding
不是可以这样吗?
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
double MAX=-50000,MIN=50000,sum=0;
int a[1001],n,i;
int main(){
cin>>n;
for(i=1;i<=n;i++){
cin>>a[i];
}
for(i=1;i<=n;i++){
if(a[i]>=MAX){
MAX=a[i];
}
if(a[i]<=MIN){
MIN=a[i];
}
sum+=a[i];
}
sum-=MAX;
sum-=MIN;
sum/=n-2;
printf("%.2lf",sum);
return 0;
}
by ZHR20100222 @ 2022-10-30 01:08:14
@kytxxxx_03
底下的数组定义没必要开
by Unreal414 @ 2022-11-04 22:42:21
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, x, mx, mn, zf = 0;
double ans;
cin >> n;
cin >> x;
mn = mx = x;
zf = x;
for (i = 2; i <= n; i++) {
cin >> x;
zf += x;
if (x >= mx)
mx = x;
if (x <= mn)
mn = x;
}
ans = ( zf - mx - mn ) * 1.0 / ( n - 2 );
cout << fixed << setprecision(2) << ans;
return 0;
}
by Kinzo @ 2022-11-09 13:45:07
#include<bits/stdc++.h>
using namespace std;
int n;
int p[1010];
int main() {
cin>>n;
int sum=0;
int mmax=0;
int mmin=114514;
double a=0;
for(int i=0; i<n; i++) {
cin>>p[i];
sum+=p[i];
if(p[i]>mmax) mmax=p[i];
if(p[i]<mmin) mmin=p[i];
}
a=1.0*(sum-mmax-mmin)/(n-2);
cout<<fixed<<setprecision(2)<<a;
return 0;
}