#include using namespace std;

void insertionSort(int arr[], int n) { for (int i = 1; i < n; i++) { int key = arr[i]; int j = i - 1; while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j--; } arr[j + 1] = key; } }

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

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

int maxHeights[M];
int avgHeights[M];
int count = 0;
for (int i = 0; i < M; i++) {
    int max_height = heights[i][0];
    int sum_height = 0;
    for (int j = 0; j < N; j++) {
        if (heights[i][j] > max_height) {
            max_height = heights[i][j];
        }
        sum_height += heights[i][j];
        if (heights[i][j] > 165) {
            count++;
        }
    }
    maxHeights[i] = max_height;
    avgHeights[i] = sum_height / N;
}

for (int i = 0; i < M; i++) {
    cout << maxHeights[i] << endl;
}

for (int i = 0; i < M; i++) {
    cout << avgHeights[i] << endl;
}

int highHeights[count];
int index = 0;
for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
        if (heights[i][j] > 165) {
            highHeights[index] = heights[i][j];
            index++;
        }
    }
}

insertionSort(highHeights, count);

for (int i = count - 1; i >= 0; i--) {
    cout << highHeights[i] << " ";
}

return 0;

}

C++ 实现舞蹈队形编排:不使用 vector 头文件,使用插入排序

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

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