84分求救!!!

B2047 分段函数

yatloimly @ 2024-10-16 23:22:22

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

by luoyebushiye @ 2024-10-17 12:46:26

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

  return 0;
}

@yatloimly

你瞅瞅看


by yatloimly @ 2024-10-17 22:06:04

@luoyebushiye okok,thank you(awa)(bu xiang zhuan huan shu ru fa)


by a23GCC @ 2024-11-01 21:16:09

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

|