60分 大神求解

P1422 小玉家的电费

zhiyinba @ 2023-07-14 23:14:01

#include<bits/stdc++.h>
using namespace std;
int n;
double ans;
int main(){
   cin>>n;
   if(n>0&&n<=150)
   {
        ans=n*0.4463;
   }
   else if(n>150&&n<=401)
   {
        ans=150*0.4463;
        n-=150;
        ans+=n*0.4663;
   }
   else
   {
        ans=150*0.4463;
        ans+=251*0.4663;
        n-=401;
        ans+=n*0.5663;
   }
   cout<<fixed<<setprecision(1)<<ans;
   return 0;
}

by Steve_xh @ 2023-07-14 23:20:18

@zhiyinba 第二个if,把n<=401改成n<400


|