题解 | #矩阵最大值#

矩阵最大值

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;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-05 10:13
已编辑
HHHHaos:让这些老登来现在秋招一下,简历都过不去
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务