#为什么只有68分?

B2047 分段函数

lapi666 @ 2023-09-24 11:08:54

#include<stdio.h>
int main(){
    double x,y;
    scanf("%lf",&x);

    if (x>=10&&x<20){
        y =x/2-15;

    }
    else if(x>=5&&x<10){
        y =2-1.5*(x-3)*(x-3);
    }

    else if(x>=0&&x<5){
        y =-x+2.5;
    }

    printf("%.3lf",y);
    return 0;
}

by DevilsFlame @ 2023-09-24 11:11:40

#include<bits/stdc++.h>
using namespace std;
int main(){
    double a;
    cin>>a;
    if(a<5)
        cout<<fixed<<setprecision(3)<<2.5-a<<endl;
    if(a>=5&&a<10)
        cout<<fixed<<setprecision(3)<<2-1.5*(a-3)*(a-3)<<endl;
    if(a>=10&&a<20)
        cout<<fixed<<setprecision(3)<<a/2-1.5<<endl;
    return 0;
}

by diandian2020 @ 2023-09-24 11:12:05

x/2-15(


by littlewhite_ @ 2023-09-24 11:29:08

#include <bits/stdc++.h>
using namespace std;

int main()
{
    double x;
    cin >> x;
    if (x >= 0 && x < 5) x = 2.5 - x;
    if (x >= 5 && x < 10) x = 2 - 1.5 * (x - 3) * (x - 3);
    if (x >= 10 && x < 20) x = x / 2 - 1.5;
    cout << fixed << setprecision(3) << x;
    return 0;
} 

by lingluyuqian @ 2023-10-19 21:21:47

我的代码

#include <bits/stdc++.h>

using namespace std;
int main() {
    double x,y;
    cin >> x;
    if(0<=x && x<5 ){
        y=-x+2.5;
        printf("%.3lf",y);
    }else if(5<=x && x<10 ){
        y=2-1.5*(x-3)*(x-3);
        printf("%.3lf",y);
    }else if(10<=x && x<20){
        y=x/2-1.5;
        printf("%.3lf",y);
    }
    return 0;
}

|