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

    你可能感兴趣的文章
    poj 3026( Borg Maze BFS + Prim)
    查看>>
    POJ 3041 - 最大二分匹配
    查看>>
    POJ 3041 Asteroids(二分匹配模板题)
    查看>>
    Qt笔记——标准文件对话框QFileDialog
    查看>>
    poj 3083 Children of the Candy Corn
    查看>>
    POJ 3083 Children of the Candy Corn 解题报告
    查看>>
    POJ 3253 Fence Repair C++ STL multiset 可解 (同51nod 1117 聪明的木匠)
    查看>>
    Qt笔记——控件总结
    查看>>
    poj 3262 Protecting the Flowers 贪心
    查看>>
    poj 3264(简单线段树)
    查看>>
    Qt笔记——布局管理三件套分割窗口、停靠窗口和堆栈窗口
    查看>>
    poj 3277 线段树
    查看>>
    POJ 3349 Snowflake Snow Snowflakes
    查看>>
    POJ 3411 DFS
    查看>>
    poj 3422 Kaka's Matrix Travels (费用流 + 拆点)
    查看>>
    Qt笔记——官方文档全局定义(二)Functions函数
    查看>>
    POJ 3468 A Simple Problem with Integers
    查看>>
    poj 3468 A Simple Problem with Integers 降维线段树
    查看>>
    poj 3468 A Simple Problem with Integers(线段树 插线问线)
    查看>>
    poj 3485 区间选点
    查看>>