为什么40分,求助

P1422 小玉家的电费

liuziyang2010 @ 2024-05-12 09:05:53

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n<=150){
        cout<<fixed<<setprecision(1)<<n*1.0*0.4463<<endl;
        return 0;
    }
    if(n>=151&&n<=400){
        n=n-150;
        cout<<fixed<<setprecision(1)<<n*1.0*0.4663+66.9<<endl;
        return 0;
    }if(n>400){
        n=n-400;
        cout<<fixed<<setprecision(1)<<n*1.0*0.5663+66.9+183.5<<endl;
        return 0;
    }
    return 0;
}

by mc_xiexie @ 2024-05-12 09:15:06

@liuziyang2010

 #include<bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    double b=0;
    cin>>n;
    if(n<=150){
        b = n*0.4463;
    }else if(n>=151&&n<=400){
        b += 150*0.4463;
        b += (n-150)*0.4663;
    }else{
        b += 150*0.4463;
        b += (400-150)*0.4663;
        b += (n-400)*0.5663;
    }
    b=int((b*10)+0.5)/10.0;
    cout<<b;
}

|