000!

P5726 【深基4.习9】打分

qjz1 @ 2023-06-16 21:22:30

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int b;
    cin>>b;
    int a[1002];
    for(int i=0;i<b;i++){
        cin>>a[i];
    }
    int s,c;
    s=99999;
    c=-1;
    for(int i=0;i<b;i++){
        if(a[i]<s){
            c=a[i];
        }
        if(a[i]>c){
            s=a[i];
        }
    }
    int u=0;
    for(int i=0;i<b;i++){
        u+=a[i];
    }
    u-=c;
    u-=s;
    double q;
    q=u/(b-2)*1.0;
    printf("%.2lf",q);
    return 0;
}

by codejiahui @ 2023-06-16 21:44:57

@tanqize1 把q的那行的*1.0放在u后面试试


by qjz1 @ 2023-06-17 13:18:19

@codejiahui 不对呀


by qjz1 @ 2023-06-17 13:26:18

@codejiahui OK了,改了一下别的


by 1000YMH @ 2023-07-26 09:30:20


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,i,s[1001],d=11,f=0;
    double g=0;
    cin>>a;
    for(i=0;i<a;i++){
        cin>>s[i];
        if(s[i]<d)d=s[i];
        if(s[i]>f)f=s[i];
    }
    for(i=0;i<a;i++)g+=s[i];
    g=(g-d-f)/(a-2);
    cout<<fixed<<setprecision(2)<<g;
}

by qjz1 @ 2023-07-26 20:28:59

@1000YMH Thanks


|