60分求助

P1422 小玉家的电费

ranbi @ 2023-10-17 12:38:47

#include <stdio.h>
int main()
{
    int dian;
    double fee=0;

    scanf("%d",&dian);

    if(dian<=150)
    {
        fee=0.4463*dian;
    }

    else if(dian<=400)
    {
        fee=0.4463*150+(dian-150)*0.4663;
    }

    else 
    {
        fee=0.4463*150+0.4463*250+(dian-400)*0.5663;
    }

    printf("%.1lf",fee);
}

by zitong_cherry @ 2023-10-17 12:41:41

精度有问题


by zitong_cherry @ 2023-10-17 12:43:07

#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    double sum=0;
    if(n<=150){
        sum+=n*0.4463;
    }
    else if(n>150&&n<=400){
        sum+=66.945;
        n-=150;
        sum+=n*0.4663;
    }
    else{
        sum+=183.52;
        n-=400;
        sum+=n*0.5663;
    }
    printf("%.1lf",sum);
    return 0;
}

by zitong_cherry @ 2023-10-17 12:44:28

如果你觉得对你有帮助请关注@rnfmabj5114谢谢喵


by zitong_cherry @ 2023-10-17 12:44:54

https://www.luogu.com.cn/user/917683


|