这就是蒟蒻的ruozhi

B2047 分段函数

lztz0503 @ 2023-10-25 10:05:31

#include <bits/stdc++.h>
using namespace std;
double x;
double ans;
void f(double x){
    if(x >= 0 && x < 5) ans = x - 2 * abs(x) + 2.5;
    else if(x >= 5 && x < 10) ans = 2 - 1.5 * (x - 3.0) * (x - 3.0);
    else if(x >= 10 && x < 20) ans = x / 2.0 - 1.5;
}
int main(){
    scanf("%1ld",x);
    f(x);
    printf("%3ld",x);
    return 0;
}

by lztz0503 @ 2023-10-25 10:05:57

怎么搞(((((


by songhongyi @ 2023-10-25 10:17:28

scanf("%1ld",&x);


by __HHX__ @ 2023-10-25 10:20:30

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

by BLuemoon_ @ 2023-10-25 10:56:39

@HHX 捉hhx


by lztz0503 @ 2023-10-25 22:10:16

@HHX 谢—————————谢大佬(


by HUTEHE @ 2023-12-18 17:03:08

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

|