HELP!! RE 0fen

P5726 【深基4.习9】打分

abssortpow1145145 @ 2024-10-13 14:06:45


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a[1005],ma=-1,mi=11,sum=0,cnt=0;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        ma=max(ma,a[i]);
        mi=min(mi,a[i]); 
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==ma || a[i]==mi)
        {
            a[i]=0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=0)
        {
            cnt++;
            sum+=a[i];
        }
    }
    printf("%.2lf",sum/cnt);
    return 0;
}

by kanqiqin @ 2024-10-13 14:16:15

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
float ans;
signed main(){
    cin >> n;
    float a[n + 1];
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    sort(a + 1,a + n + 1,greater<float>());
    for(int i = 2; i <= n - 1;i++){
        ans += a[i];
    }
    cout << fixed << setprecision(2) << ans / (n - 2) << endl;
    return 0;
}

可以借鉴: printf里最好用printf("%.2lf",sum/cnt*1.0);


by kanqiqin @ 2024-10-13 14:34:39

看了半天,你n到哪里去了???

完整代码,以你思路:

#include <bits/stdc++.h>
using namespace std;
long long n,x[1005],maxx=0,minx=10,sum;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i];
    }
    for(int i=1;i<=n;i++){
        maxx=max(maxx,x[i]);
        minx=min(minx,x[i]);
    }
    for(int i=1;i<=n;i++){
        sum+=x[i];
    }
    sum=sum-maxx-minx;
    printf("%.2lf",sum*1.0/(n-2));
    return 0;
}

@abssortpow1145145 (球关


by abssortpow1145145 @ 2024-10-13 14:39:30

@kanqiqin 找了大半天,发现n没输入。我也是检查的时候才发现。谢谢!求互关


|