40求助

P1422 小玉家的电费

liruizhou_lihui @ 2023-09-04 20:02:49

#include<bits/stdc++.h> 
using namespace std;
int main(){
    float a;
    cin>>a;
    if(a<=150) cout<<fixed<<setprecision(1)<<a*1.0*0.4463-3;
    else if(a>=151 && a<400) cout<<fixed<<setprecision(1)<<a*1.0*0.4663-3;
    else if(a>=401) cout<<fixed<<setprecision(1)<<a*1.0*0.5663-3;
}

by masiyudr @ 2023-09-04 20:06:58


#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int a;
    double n;
    cin>>a;
    if(a<=150) n=0.4463*a;
    if(a>150&&a<=400) n=0.4463*150+(a-150.0)*0.4663;
    if(a>=400) n=0.4463*150+250*0.4663+(a-400.0)*0.5663;
    cout<<fixed<<setprecision(1)<<n;
    return 0;
}···

by HASPID @ 2023-09-04 20:45:53

a<=400應該是


|