60分2,5war求大家帮忙,在自己的程序软件上是对的

P1422 小玉家的电费

hgdhjgj @ 2024-03-05 17:24:46

#include<stdio.h>
int main(){
    int n;
    double t;
    scanf("%d",&n);
    if(n<=400){
        if(n<=150){
            t=n* 0.4463;
           printf("%.1lf",t); 
        }else{
            t=150*0.4463+(n-150)*0.4663;
            printf("%.1lf",t);
        }
    }else{
        t=150*0.4463+(400-150)*0.4663+(n-400)*0.5663;
        printf("%,1lf",t);
    }
    return 0;
}

by Aybbl_xc @ 2024-03-05 17:27:17

@hgdhjgj 倒数第四行

printf("%,1lf",t);

改成

printf("%.1lf",t);

by hgdhjgj @ 2024-03-05 20:55:03

@Aybbl_xc 谢谢


by LamGaaSing @ 2024-03-06 16:17:55

#include <bits/stdc++.h>
using namespace std;
const float low = 0.4463;
const float middle = 0.4663;
const float high = 0.5663;

int main() {
    float x , z1 = 0.0, z2 = 0.0, z3 = 0.0;
    float sum = 0;
    cin >> x;
    z1 = x - 400 <= 0 ? 0 : x - 400;
    z2 = z1 > 0 ? 400 - 150 : ((x - 150) > 0 ? x-150 : 0 );
    z3 = z2 > 0 ? 150 : x;

    sum = z1*high + z2 * middle + z3 * low;
    cout << fixed << setprecision(1) << sum;
    return 0;
}

可以试一下这个


by Lorentz @ 2024-03-09 15:58:30

@Aybbl_xc 为什么我没看出来区别


by hxbhxb @ 2024-03-29 16:27:31

@Lorentz 一个是,一个是.


|