p1422小玉家的电费

P1422 小玉家的电费

xqq201408 @ 2024-09-24 20:43:54

20分,高手救救我。


by zhkkk_ @ 2024-09-24 20:45:02


by xqq201408 @ 2024-09-27 18:46:08

#include<bits/stdc++.h>
using namespace std;

int main()
    {
    long long a;
    double b;
    a=0;
    b=0;
    cin>>a;
        if(a<=150)
    {
        b = a*0.4463;
    }
    else if(a>=151&&a<=400)
    {
        b += 150*0.4463;
        b += (a-150)*0.4663;
    }
    else
    {
        b += 150*0.4463;
        b += (400-150)*0.4663;
        b += (a-400)*0.5663;
    printf("%.1lf",b);
    return 0;
    }

在这里


by hh15903737128 @ 2024-09-28 11:04:14

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

AC代码


by tangyiqi @ 2024-10-04 14:18:38

@xqq201408
用我的AC代码吧

#include <bits/stdc++.h>
using namespace std;
int a;
double price = 0.0;
double dian1(int x);
double dian2(int x);
double dian3(int x);
void print(double x);
int main(){
    scanf("%d",&a);
    if(a<=150)print(dian1(a));
    else if(a>150 && a<=400)print(dian2(a));
    else print(dian3(a));
    return 0;
}
double dian1(int x){
    price+=x*1.0*0.4463;
    return price;
}
double dian2(int x){
    price+=1.0*0.4463*150+(x-150)*1.0*0.4663;
    return price;
}
double dian3(int x){
    price+=1.0*0.4463*150+(400-150)*1.0*0.4663+(x-400)*1.0*0.5663;
    return price;
}
void print(double x){
    printf("%.1lf",x); 
}

你的代码我一会帮你看看


by tangyiqi @ 2024-10-04 14:29:32

@xqq201408
1.你的main函数忘记加后括号了
2.你的return 0;printf("%.1lf",b);放错位置了,应该放在else的大括号之外。
以下就是正确且规范的你的改进后的代码

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

话说你不能在本地跑通后再提交吗???
求关,求加团


|