玄关,求调

P5726 【深基4.习9】打分

Liuzr20 @ 2024-08-30 18:00:36

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[10005],sum=0;
    double x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n);
    sum-=a[0];
    sum-=a[n-1];
    x=sum/(n-2);
    printf("%.2f",x);
    return 0;
}

by dream_dad @ 2024-08-30 18:05:08

@Liuzr20


#include<bits/stdc++.h>
 using namespace std;
int main()
{   int n,a[10001],sum=0;
    double x;
    cin>>n;
    for(int i=0;i<n;i++){
      cin>>a[i];
   }
    sort(a,a+n);
    for(int i=1;i<n-1;i++)
      x+=a[i];
    printf("%.2lf",x/(n-2));
    return 0;
}

by Eason20120229 @ 2024-08-30 18:05:53

@Liuzr20 x=sum/(n-2); 改为 x=sum * 1.0/(n-2); 因为整数相除,结果为整数,求关注。


by Liuzr20 @ 2024-08-30 18:12:23

@dream_dad 感谢,已关


by fangkai123 @ 2024-08-30 18:17:34

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int max=-1,min=11;
    int sum = 0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        sum+=x;
        if(x>max){
            max = x;
        }
        if(x<min){
            min = x;
        }
    } 
    double average = sum-min-max;
    printf("%.2lf",average/(n-2));
    return 0;
} 

|