60求指点

P1422 小玉家的电费

awdfkewd @ 2024-11-06 21:40:21

#include <iostream>
#include <iomanip>
using namespace std; 
int a;
double b=0;
int main(){
    cin>>a;
    if(a>=150){
        b+=150*0.4463;
        if(a>=400){
            b+=250*0.4663;
            b+(a-400)*0.5663;
        }else{
            b+=(a-150)*0.4664;
        }
    }else{
        b+=a*0.4463;
    }
    cout<<fixed<<setprecision(1)<<b;
}

by wuyusheng @ 2024-11-06 21:47:58

@awdfkewd

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    double sum;
    cin>>n;
    if(n<=150)
    sum=n*0.4463;
    else if(n>=151&&n<=400)
    sum=150*0.4463+(n-150)*0.4663;
    else
    sum=150*0.4463+(400-150)*0.4663+(n-400)*0.5663;
    printf("%.1f",sum);
}

by Il1_1_3 @ 2024-11-06 21:48:10

b+=(a-150)*0.4664;

这里应该是 0.4663 @awdfkewd


by awdfkewd @ 2024-11-06 21:58:25

@Il1_1_3 谢谢,眼睛不好使,都关注了


|