题解 | #矩阵最大值#
矩阵最大值
https://www.nowcoder.com/practice/9c550b6fe85d48bcad5a6025c6dc447d
#include <iostream> using namespace std; const int MAXN = 100 + 10; int matrix[MAXN][MAXN]; int main () { int m, n; while (cin >> m >> n){ for (int i = 0; i < m; i++){ for (int j = 0; j < n; j++){ cin >> matrix[i][j]; } } for (int i = 0; i < m; i++){ int maxnum = matrix[i][0], maxj = 0, rowsum = 0; for (int j = 0; j < n; j++){ if (matrix[i][j] > maxnum){ maxnum = matrix[i][j]; maxj = j; } rowsum += matrix[i][j]; } matrix[i][maxj] = rowsum; } for (int i= 0; i < m; i++){ for (int j = 0; j < n; j++){ cout << matrix[i][j] << " "; } cout << endl; } } return 0; }