思路及代码
//input 10组 statics
//6 int
#include<iostream>
using namespace std;
int main(){
int list[10][7];
for (int i = 0; i <= 9; i++){
int sum_score = 0;
cin >> list[i][0];
//solution
//initial 10*7 静态数组
for (int j = 1; j <= 5; j++){
cin >> list[i][j];
sum_score += list[i][j];
}
list[i][6] = sum_score;
}
//sort by sum_score
int i = 9;
while(i--){
for (int row = 0; row <= i ; row++){
if(list[row][6] > list[row+1][6]){
swap(list[row],list[row+1]);
}
}
}
//output
cout << list[9][0] << ' ' << list[9][6] << endl;
cout << list[0][0] << ' ' << list[0][6] << endl;
return 0;
}
参考:1️⃣【编程】二维数组按照某行或某列排序(c++实现)_c++ 二维数组中指定列排序-CSDN博客
2️⃣简单而经典:Java中的冒泡排序算法详解-阿里云开发者社区
3️⃣swap() in C++ - GeeksforGeeks
收获:1️⃣复习冒泡排序 相邻元素
2️⃣swap(a,b)
swap(a, b)
// swaps the value of two variables.
// two mandatory parameters a and b which are to be swapped. The parameters can be of any data type.
//Time Complexity: O(1),Space Complexity: O(1)
菜菜,不是教程,做题和学习记录