60分,求助

P1422 小玉家的电费

Dingym123456 @ 2024-07-26 15:50:41

#include<bits/stdc++.h>
#define M 101010
#define N 1010
#define ll long long
using namespace std;

ll re(){
    ll s = 0, f = 1; char c = getchar();
    for(; !isdigit(c); c = getchar())
        if(c == '-') f = -1;
    for(;  isdigit(c); c = getchar())
        s = s * 10 + c - '0';
    return f * s;
}

int main(){
    int d;
    d = re();
    double mon;
    if(d <= 150)mon = 0.4463*d;
    else if(d >= 151&&d <= 400)mon = 66.945 + (d - 150)*0.4663;
    else if(d >= 401)mon = 182.52 + (d - 400)*0.5663;
    printf("%.1f",mon);

    return 0;
}

by cute_ @ 2024-07-26 15:55:38

稍等 我看看


by cute_ @ 2024-07-26 16:05:21

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
    if(n<=150) cout<<double(int(0.4463*n*10))/10;
    else if(n>150&&n<=400) cout<<double(int((150*0.4463+(n-150)*0.4663)*10))/10;
    else cout<<double(int((150*0.4463+250*0.4663+(n-400)*0.5663)*10))/10;
}

60分 我看看哪里出问题了


by Dingym123456 @ 2024-07-26 16:06:14

@cute_ 嗯


by cute_ @ 2024-07-26 16:08:48

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
    if(n<=150) cout<<double(int(0.4463*n*10+0.05))/10;
    else if(n>150&&n<=400) cout<<double(int((150*0.4463+(n-150)*0.4663+0.05)*10))/10;
    else cout<<double(int((150*0.4463+250*0.4663+(n-400)*0.5663+0.05)*10))/10;
}

果然,要四舍五入评测结果


by cute_ @ 2024-07-26 16:10:14

草 早知道看题解了 调了我3分钟。。。。


by Dingym123456 @ 2024-07-26 16:10:42

@cute_ 我四舍五入了呀?!


by cute_ @ 2024-07-26 16:11:09

第一个0.05放错位置了但是也过了


by cute_ @ 2024-07-26 16:12:04

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
    if(n<=150) cout<<double(int(0.4463*n*10+0.5))/10;
    else if(n>150&&n<=400) cout<<double(int((150*0.4463+(n-150)*0.4663+0.05)*10))/10;
    else cout<<double(int((150*0.4463+250*0.4663+(n-400)*0.5663+0.05)*10))/10;
}

这个


by cute_ @ 2024-07-26 16:12:42

@Dingym123456 我看看


by cute_ @ 2024-07-26 16:13:55

@Dingym123456 你哪四舍五入了 没看出来。。


| 下一页