为啥不对啊,例子运行结果是对的

B2095 白细胞计数

MIKE_2300980135 @ 2024-04-07 16:58:12

#include <stdio.h>
#include <math.h>
void sort(float *a,int n)
{
    int i,j;
    float t;
    for(i=1;i<n;i++)
    {
        for(j=n-1;j>=i;j--)
        {
            if(*(a+j)<=*(a+j-1))
            {
                t=*(a+j);
                *(a+j)=*(a+j-1);
                *(a+j-1)=t;
            }
        }
    }
}
float hanshu1(float *a,int n)
{
    float s=0;
    int i;
    for(i=1;i<n-1;i++)
    {
        s+=*(a+i);
    }
    return s;
}
float hanshu2(float *a,int n,int p)
{
    float m,r,k;
    m=fabs(*(a+1)-p);
    r=fabs(*(a+n-2)-p);
    k=m>r?m:r;
    return k; 
}
int main()
{
    int n,i;
    scanf("%d",&n);
    float a[300]={0};
    for(i=0;i<n;i++)
    {
        scanf("%f",a+i);
    }
    sort(a,n);
    float p=hanshu1(a,n)*1.0/(n-2);
    printf("%.2f",hanshu1(a,n)/(n-2));
    printf(" %.2f",hanshu2(a,n,p));
    return 0;
}

by cdxxmashaoyang @ 2024-04-07 17:22:16

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

给个关注吧,能不能加一下www.luogu.com.cn/team/60983


by MIKE_2300980135 @ 2024-04-07 17:26:02

@cdxxmashaoyang 大佬,C++还没学


by cdxxmashaoyang @ 2024-04-07 17:31:13

行,我回家再想办法,这会儿在上课


by MIKE_2300980135 @ 2024-04-07 17:31:52

@cdxxmashaoyang 感谢感谢


|