20分求助

P1422 小玉家的电费

liuzixuancluo @ 2024-10-04 19:58:48

#include <iostream>
#include <cstdio>
using namespace std;

int main(int argc, char** argv) {
    int n;
    cin>>n;
    if(n<150)
    {
        printf("%.1f",n*0.4463); 
    }
    if(n>=150&&n<=400)
    {
        printf("%.1f",n*0.4663);
    }
    if(n>=401)
    {
        printf("%.1f",n*0.5663);
    }
    return 0;
}

by Lazy_crush @ 2024-10-04 20:03:27

题意理解有误

code:

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

|