以下是C++的实现代码:

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main() {
    int M, N;
    std::cin >> M >> N;

    std::vector<std::vector<int>> heights(M, std::vector<int>(N));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            std::cin >> heights[i][j];
        }
    }

    std::vector<int> max_heights(N);
    for (int j = 0; j < N; j++) {
        int max_height = heights[0][j];
        for (int i = 1; i < M; i++) {
            max_height = std::max(max_height, heights[i][j]);
        }
        max_heights[j] = max_height;
    }

    std::sort(max_heights.rbegin(), max_heights.rend());

    std::vector<int> all_heights;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            all_heights.push_back(heights[i][j]);
        }
    }
    std::sort(all_heights.rbegin(), all_heights.rend());

    int sum_heights = 0;
    for (int height : all_heights) {
        sum_heights += height;
    }
    int average_height = std::round((double)sum_heights / all_heights.size());

    int count_above_average = 0;
    for (int height : all_heights) {
        if (height >= average_height) {
            count_above_average++;
        }
    }

    for (int height : max_heights) {
        std::cout << height << std::endl;
    }
    for (int height : all_heights) {
        std::cout << height << " ";
    }
    std::cout << std::endl;
    std::cout << average_height << std::endl;
    std::cout << count_above_average << std::endl;

    return 0;
}

该代码首先读取输入的矩阵大小和身高数据,然后按照题目要求进行计算和输出。首先,使用两个嵌套循环找出每列身高的最大值,将其存储在max_heights向量中。然后,将所有学生的身高存储在all_heights向量中,并按照从高到低的顺序进行排序。接下来,计算所有学生的身高总和并计算平均身高。最后,统计不小于平均身高的学生人数。最后,按照题目要求输出结果

C++实验小学为了强健学生的身体每天课间都要组织学生在户外学做广播体操。这一天五年级三班的所有同学在老师的指引下将队形排成了M行N列。 现已知所有同学的身高数值为整数单位:厘米。要求在所有同学中:1挑选出每列身高最高的同学作为此列的小队长为同学们带操;2将所有同学按身高从高到低的顺序进行排队;3求出所有同学们的平均身高要求:四舍五入保留整数;4统计出不小于平均身高的学生人数。 请同学们用计算机编程

原文地址: http://www.cveoy.top/t/topic/hXEW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录