帮我找一下错

A. 计算邮资

Problem ID: 6024

Contest ID: 5844

必做题

Wrong Answer

10 分

计算邮资

【问题描述】

快递行业为现在的社会提供了极大的方便,促进了社会的极大发展,那当我们自己需要邮寄一些东西的时候,就需要知道邮费的计算规则才行,邮费是根据邮件的重量和用户是否选择加急计算的。计算规则如下:

重量在1000克以内(包含1000克),基本费8元;超过1000克的部分,每500克加收超重费4元,不足500克部分按500克计算;如果用户选择加急,多收5元。

【输入描述】

输入一行,包含整数n(1<=n<=1000000)和一个字符c,以一个空格分开,分别表示重量(单位为克)和是否加急。

如果字符是 y,表示选择加急;如果字符是 n,表示不加急。

【输出描述】

一行,包含一个整数,表示邮费。

【样例输入】

1200 y

【样例输出】

17

WA10分代码

#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,s=0;char c;
    cin>>a>>c;
    if(a>1000){
        s+=8;
        a-=1000;
        if(a<=500){
            s+=4;
            if(c=='y'){
                s+=5;
            }
            else{
                s+=0;
            }
        }
        else{
            s+=a/500*4;
            if(c=='y'){
                s+=5;
            }
            else{
                s+=0;
            }
        }
    }
    else{
        s+=8;
        if(c=='y'){
			s+=5;
		}
    }
    cout<<s;
}
1 个赞
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;//表示重量 
    int a;//存放重量超过1000克的部分 
    int s=0;//邮资 
    cin>>n;//输入重量 
    char m;//表示是否加急 
    cin>>m;//输入是否加急 
    if(n<=1000){
        s+=8;
        //判断重量是否小于1000 
    }
    else{
        s+=8;//基本费 
        a=n-1000;//超过1000的部分 
        while(a>0){//计算超出1000部分的邮资 
              s+=4;
            a-=500;
        }
    }
    if(m=='y'){//判断是否加急 
        s+=5;
    }
    cout<<s;//输出最后邮资 

    return 0;
}
2 个赞

#include
#include
using namespace std;
int n,s=8;
char c;
int main(){
cin>>n>>c;
if(n>1000){
double x=(n-1000)/500;
s+=ceil(x)*4;
}
if(c=‘y’){
s+=5;
}
cout<<s;
return 0;
}我也错的 :sweat_smile:

1 个赞

这些是干什么的decide result

1 个赞

一个是自定义函数,一个是变量

1 个赞

问题很大啊

1 个赞
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;//表示重量 
    int a;//存放重量超过1000克的部分 
    int s=0;//邮资 
    cin>>n;//输入重量 
    char m;//表示是否加急 
    cin>>m;//输入是否加急 
    if(n<=1000){
        s+=8;
        //判断重量是否小于1000 
    }
    else{
        s+=8;//基本费 
        a=n-1000;//超过1000的部分 
        while(a>0){//计算超出1000部分的邮资 
              s+=4;
            a-=500;
        }
    }
    if(m=='y'){//判断是否加急 
        s+=5;
    }
    cout<<s;//输出最后邮资 

    return 0;
}