博客
关于我
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/

    你可能感兴趣的文章
    Notes on Paul Irish's "Things I learned from the jQuery source" casts
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    NotImplementedError: Could not run torchvision::nms
    查看>>
    nova基于ubs机制扩展scheduler-filter
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack‘解决方法
    查看>>
    npm ERR! ERESOLVE could not resolve报错
    查看>>
    npm ERR! fatal: unable to connect to github.com:
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
    查看>>
    npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
    查看>>
    npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
    查看>>
    npm install CERT_HAS_EXPIRED解决方法
    查看>>
    npm install digital envelope routines::unsupported解决方法
    查看>>