a?为何68

B2047 分段函数

AAAuc03 @ 2024-08-23 19:01:47

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

by wyc0607 @ 2024-08-23 19:05:29

@AAAuc03 已过,求关


#include <bits/stdc++.h>
using namespace std;
int main()
{
    double x;
    cin>>x;
    double a=-x+2.5,b=2.0-1.5*(x-3.0)*(x-3.0),c=x/2.0-1.5;
    if(x>=0&&x<5) printf("%.3f",a);//符号写反,x>=0 
    else if(x>=5&&x<10) printf("%.3f",b);//符号写反,x>=5 
    else if(x>=10&&x<20) printf("%.3f",c);//符号写反,x>=10 
    return 0;
}

by hyl_____ @ 2024-08-23 19:06:30

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

by hyl_____ @ 2024-08-23 19:07:21

晚了一丢丢喵


by chenzhishuo2012 @ 2024-09-03 07:51:27

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

|