救命!!!

B2047 分段函数

yaojinghong @ 2023-11-03 13:14:36

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

68分,1和3两个点错了,为什么啊


by GoodLuckCat @ 2023-11-03 13:29:49

@yaojinghong a 变量要用 double


by yaojinghong @ 2023-11-03 22:29:42

@Huyuhao0215 过了,谢(鞠躬)


|