60分,求救!

P1422 小玉家的电费

JshGLJ @ 2023-07-31 22:27:49

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    double a,b,sum=0;
    cin>>n;
    if(n<=150){
      sum=n*0.4463;
    }else if(n<=400){
      a=n-150;
      sum=n*0.4463+a*0.4663;
    }else{
      b=n-400;
      sum=150*0.4463+250*0.4663+b*0.5663;
    }
    cout<<setprecision(1)<<std::fixed<<sum;
    return 0;
}

by ybc2025chenyuyang @ 2023-07-31 22:38:04

@LIUSASA 大哥,你是小学分段计费没学好么? 看第二个判断,n<=400那个,sum是不是算错了,应该是用150*0.4463啊 祭验证码 8kkk


by JshGLJ @ 2023-08-01 15:03:38

@ybc2025125chenyuyang 谢谢


|