一个40的(不知道会不会被理)

P1422 小玉家的电费

Iochi_YC @ 2024-12-27 23:57:15

#include <bits/stdc++.h>
using namespace std;
double man,bou;
int main() {
    cin>>man;
    if(man<=150){
         cout<<fixed<< setprecision(1)<<man*0.4463;
        man-=149;
    }if(man>=151||man<=400){
         cout<<fixed<< setprecision(1)<<man*0.4663;
         man-=400;
    }if(man>=401){
       cout<<fixed<< setprecision(1)<<man*0.5663;
    }

    return 0;
}

In:267

Out:124.5

哪里多的三啊!!!


by 11514zbs @ 2024-12-28 07:50:09

@Iochi_YC 这是分段计费。

#include <bits/stdc++.h>
using namespace std;
int man;
int main() {
    cin>>man;
    if(man<=150){
         cout<<fixed<< setprecision(1)<<man*0.4463;
    }else if(man<=400){
         cout<<fixed<< setprecision(1)<<150*0.4463+(man-150)*0.4663;
    }else{
       cout<<fixed<< setprecision(1)<<150*0.4463+250*0.4663+(man-400)*0.5663;
    }
    return 0;
}

by zhangtongxue20130117 @ 2024-12-28 08:18:12

盖乐已瞎

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

by weis @ 2024-12-28 09:14:30

本来想在你的基础上做改变,结果除了头文件和变量的定义没一个有用的,还有与运算时是&&不是||,这是你的主要问题

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

    return 0;
}

by Iochi_YC @ 2024-12-28 23:44:42

@weis@zhangtongxue20130117@11514zbs万分感谢以上三位大佬


|