博客
关于我
L1-040 最佳情侣身高差 (10分)
阅读量:392 次
发布时间:2019-03-05

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

最佳情侣身高差的计算公式为:女方的身高乘以1.09等于男方的身高。因此,当已知一方的身高和性别时,可以通过公式计算另一方的最佳身高。具体步骤如下:

  • 读取输入的用户数N。
  • 对于每个用户,读取其性别和身高。
  • 根据性别判断计算另一方的身高:
    • 若用户为男性,则女方的身高为男方身高除以1.09。
    • 若用户为女性,则男方的身高为女方身高乘以1.09。
  • 将计算结果保留两位小数输出。
  • 以下是实现代码:

    #include 
    using namespace std;int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { char c; double a; cin >> c >> a; if (c == 'M') { cout << fixed << setprecision(2) << a / 1.09 << endl; } else { cout << fixed << setprecision(2) << a * 1.09 << endl; } } return 0;}

    代码解释:

  • 包含必要的标准库头文件。
  • 读取用户数量N。
  • 对于每个用户,读取性别字符c和身高a。
  • 根据性别判断,使用相应的公式计算另一方的最佳身高。
  • 使用fixedsetprecision(2)确保输出格式为小数点后两位。
  • 输出结果。
  • 该代码能够正确处理用户输入并计算最佳情侣身高,满足题目要求。

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

    你可能感兴趣的文章
    Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
    查看>>
    NMAP网络扫描工具的安装与使用
    查看>>
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>