求助 一个AC

P1422 小玉家的电费

sfvthg @ 2024-12-16 14:24:15

输入为267 输出为54.1

#include<bits/stdc++.h>
using namespace std;
int main(){
  double all,sum=0;
  scanf("%lf",&all);
  if(all>=401){
    double a=all-401;
    sum+=a*0.5663;
    all-=a;
  }
  if(all<401 && all>=151){
    double b=all-151;
    sum+=b*0.4663;
    all-=b;
  }
  if(all<150){
    sum+=all*0.4463;
  }
  printf("%.1f",sum);
  return 0;
}  

by YuYi_official @ 2024-12-16 19:27:53

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;  //整数存用电度数 
    double b; //双精度浮点存金额 
    cin>>a;   
    if (a<150 || a==150){
        b=0.4463*a;             
        cout<<fixed<<setprecision(1)<<b<<endl;  //保留一位小数 
    }else if((150<a && a<400) || a==400){
        b=0.4663*(a-150) + (150*0.4463);
        cout<<fixed<<setprecision(1)<<b<<endl;
    }else{
        b=0.5663*(a-400) + (250*0.4663) + (0.4463*150);
        cout<<fixed<<setprecision(1)<<b<<endl;
    } 
}

by YuYi_official @ 2024-12-16 19:30:09

@sfvthg 阶梯收费要将上一阶梯费用加上!


by sfvthg @ 2024-12-19 09:19:03

@YuYi_official 谢谢提醒


|