博客
关于我
2021-05-09
阅读量:535 次
发布时间:2019-03-09

本文共 724 字,大约阅读时间需要 2 分钟。

出租车费计算方式

根据题目描述,出租车的收费规则分为以下几个部分:

  • 起步价:2公里以内的费用为7元,包含这2公里。
  • 超过2公里但不超过15公里的部分,每公里收费1.5元。
  • 超过15公里的部分,每公里收费2.1元。
  • 需要注意的是,如果乘车里程不足1公里,也会按1公里计算,即收费1元。

    在实际计算时,需要对乘车里程s进行分段处理:

    • 如果s小于等于2公里,税费为7元。
    • 如果s在2公里到15公里之间,税费=7元+(s-2公里部分的每公里费用)。
    • 如果s超过15公里,税费=7元+2公里到15公里的费用+超过15公里部分的费用。

    代码实现思路

    #include 
    #include
    #include
    using namespace std; int main(){ double s; cin >> s; double tax = 0; if(s <= 2){ tax = 7; } else if(s > 2 && s <=15){ tax = 7 + (ceil(s) - 2) * 1.5; } else { tax = 7 + 13 * 1.5 + (ceil(s) - 15) * 2.1; } cout << fixed << setprecision(6); cout << tax << endl; }

    请注意代码中使用了ceil函数来向上取整,以确保不足1公里的部分按1公里计算。

    转载地址:http://cqoiz.baihongyu.com/

    你可能感兴趣的文章
    npm install CERT_HAS_EXPIRED解决方法
    查看>>
    npm install digital envelope routines::unsupported解决方法
    查看>>
    npm install 卡着不动的解决方法
    查看>>
    npm install 报错 EEXIST File exists 的解决方法
    查看>>
    npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
    查看>>
    npm install 报错 Failed to connect to github.com port 443 的解决方法
    查看>>
    npm install 报错 fatal: unable to connect to github.com 的解决方法
    查看>>
    npm install 报错 no such file or directory 的解决方法
    查看>>
    npm install 权限问题
    查看>>
    npm install报错,证书验证失败unable to get local issuer certificate
    查看>>
    npm install无法生成node_modules的解决方法
    查看>>
    npm install的--save和--save-dev使用说明
    查看>>
    npm node pm2相关问题
    查看>>
    npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
    查看>>
    npm run build报Cannot find module错误的解决方法
    查看>>
    npm run build部署到云服务器中的Nginx(图文配置)
    查看>>
    npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
    查看>>
    npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
    查看>>
    npm scripts 使用指南
    查看>>
    npm should be run outside of the node repl, in your normal shell
    查看>>