求大佬帮帮我

P1422 小玉家的电费

WXY_ShiXiaoJi @ 2024-07-30 09:05:35

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

by Ahws_rwhy @ 2024-07-30 09:21:39

@j20130930j

#include <bits/stdc++.h>
using namespace std;
int n;
double ans;
int main() {
    cin >> n;
    int t = n;
    if(t <= 150) {ans = 0.4463 * t;}
    if(n > 150) {
//      n -= 150;
        if(n < 401) ans = (double)0.4463 * 150.0 + 0.4663 * (n - 151 + 1) * 1.0;
//      else n -= 249;
        if(n > 400) ans = 0.4463 * 150 + 0.4663 * 250 + 0.5663 * (n - 400);
    }
//  if(n > 0) {
//      ans += 0.5663 * n;
//  }
    printf("%.1f",ans);
    return 0;
}

by WXY_ShiXiaoJi @ 2024-07-30 09:29:17

@rwhy 谢谢


|