博客
关于我
FZU 1629 Above Average
阅读量:152 次
发布时间:2019-02-27

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

解决方案:

首先,我们需要读取输入数据。输入的第一行是一个整数C,表示测试用例的数量。接下来的C行,每一行都对应一个测试用例。每个测试用例的第一行是一个整数N,表示班级的学生人数,接下来的N个整数是该班学生的成绩。

对于每个测试用例,我们需要做以下步骤:

  • 计算所有学生的平均分。
  • 统计有多少学生的成绩高于平均分。
  • 计算这些学生所占的比例,并将结果格式化为百分比,保留三位小数。
  • 具体步骤如下:

  • 读取输入数据。
  • 对于每个测试用例,计算平均分。
  • 统计高于平均分的学生数。
  • 计算百分比并输出。
  • 以下是实现代码:

    #include 
    #include
    #include
    #include
    using namespace std;int main() { int C; cin >> C; for (int i = 0; i < C; ++i) { int N; cin >> N; vector
    scores; for (int j = 0; j < N; ++j) { int score; cin >> score; scores.push_back(score); } double average = accumulate(scores.begin(), scores.end(), 0.0) / N; int above_avg = 0; for (int k = 0; k < N; ++k) { if (scores[k] > average) { ++above_avg; } } double percentage = (static_cast
    (above_avg) / N) * 100.0; cout << fixed << setprecision(3) << percentage << "%"; } return 0;}

    这个代码实现了问题要求的所有步骤。它首先读取输入数据,计算平均分,然后统计高于平均分的学生数,并将结果格式化为百分比输出。代码结构清晰,易于理解和维护。

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

    你可能感兴趣的文章
    projection介绍及EPSG:4326和EPSG:3857的投射转换
    查看>>
    project打开文件时,显示无法识别此文件格式?
    查看>>
    Prometheus + Grafana on Kubernetes部署
    查看>>
    prometheus + grafana进行服务器资源监控
    查看>>
    Prometheus Alertmanager 告警配置详解
    查看>>
    Prometheus Grafana 展示平台
    查看>>
    Prometheus pushgateway使用详解
    查看>>
    Prometheus 云原生 - Prometheus 数据模型、Metrics 指标类型、Exporter 相关
    查看>>
    Prometheus 云原生 - 基于 file_sd、http_sd 实现 Service Discovery
    查看>>
    Prometheus 云原生 - 微服务监控报警系统 (Promethus、Grafana、Node_Exporter)部署、简单使用
    查看>>
    Prometheus 云原生 - 监控 Linux、MySQL、Redis、RabbitMQ、Docker、SpringBoot 3.x
    查看>>
    Prometheus 介绍
    查看>>
    Prometheus 安全配置详解
    查看>>
    prometheus 安装node_exporter, node_exporter 安装最新版 普罗米修思安装监控服务器client
    查看>>
    Prometheus 安装部署实战
    查看>>
    prometheus 持久化存储方案
    查看>>
    Prometheus 监控系统企业级实战
    查看>>
    Prometheus 监控系统简介
    查看>>
    Prometheus 配置详解
    查看>>
    Prometheus 采集器使用详解
    查看>>