C语言期末:Problem A: 运费计算

本文介绍了一个运输公司的运费计算方法,根据路程的远近提供不同的折扣,并通过示例演示了如何根据给定的距离、货物重量和基本运费来计算最终的运费。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem A: 运费计算

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 1088   Solved: 203
[ Submit][ Status][ Web Board]

Description

某运输公司对用户按照路程计算每公里运费。路程越远,每公里运费越低。运费标准如下:
    路程km        折扣 
    s<250         无折扣 
    250<=s<500    2% 
    500<=s<1000   5% 
    1000<=s<2000  8% 
    2000<=s<3000  10% 
    s>=3000       15% 
假设每公里每吨货物的基本运费为p元,货物重量为w吨,距离为s公里。

Input

输入基本运费p(p<10),距离s(s<4000),货物重量w(w<1000),均为浮点数。

Output

输出运费,四舍五入到十元。

Sample Input

1 24 32

Sample Output

770

HINT

Append Code

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    double p,s,w;
    int m,b,c;
    scanf("%lf%lf%lf",&p,&s,&w);
    if(s<250)
    {
         m=(int)(p*s*w);
         if(m%10>=5)
         {
             b=m%10;
             c=10-b+m;
           printf("%d",c);
         }
         else
         {
             b=m%10;
             c=m-b;
           printf("%d",c);
         }

    }
    if(s>=250&&s<500)
    {
         m=(int)(p*s*w*0.98);
         if(m%10>=5)
         {
             b=m%10;
             c=10-b+m;
           printf("%d",c);
         }
         else
         {
             b=m%10;
             c=m-b;
           printf("%d",c);
         }

    }
    if(s>=500&&s<1000)
    {
         m=(int)(p*s*w*0.95);
         if(m%10>=5)
         {
             b=m%10;
             c=10-b+m;
           printf("%d",c);
         }
         else
         {
             b=m%10;
             c=m-b;
           printf("%d",c);
         }

    }
    if(s>=1000&&s<2000)
    {
         m=(int)(p*s*w*0.92);
         if(m%10>=5)
         {
             b=m%10;
             c=10-b+m;
           printf("%d",c);
         }
         else
         {
             b=m%10;
             c=m-b;
           printf("%d",c);
         }

    }
    if(s>=2000&&s<3000)
    {
         m=(int)(p*s*w*0.9);
         if(m%10>=5)
         {
             b=m%10;
             c=10-b+m;
           printf("%d",c);
         }
         else
         {
             b=m%10;
             c=m-b;
           printf("%d",c);
         }

    }
    if(s>=3000)
    {
         m=(int)(p*s*w*0.85);
         if(m%10>=5)
         {
             b=m%10;
             c=10-b+m;
           printf("%d",c);
         }
         else
         {
             b=m%10;
             c=m-b;
           printf("%d",c);
         }

    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五阿哥爱跳舞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值