题解 | #矩阵最大值#

矩阵最大值

https://www.nowcoder.com/practice/9c550b6fe85d48bcad5a6025c6dc447d

#include<iostream>

using namespace std;

int main() {
    int m, n;
    cin >> m >> n;
    int** a = new int* [m];
    for (int i = 0; i < m; i++) {
        a[i] = new int[n];
        for (int j = 0; j < n; j++)cin >> a[i][j];
        int max = 0, sum = 0;
        for (int j = 0; j < n; j++) {
            if (a[i][j] > a[i][max])max = j;
            sum += a[i][j];
        }
        a[i][max] = sum;
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++)cout << a[i][j] << " ";
        cout << endl;
    }
    return 0;
}

全部评论

相关推荐

努力成为C语言高手:质疑大祥老师,理解大祥老师,成为大祥老师
点赞 评论 收藏
分享
CrazyBucket:我今天下午也做梦在招聘会上面试一家小厂,给自己气笑了
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务