AcWing 3603. 矩阵最大值
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e2 + 10;
int t, n, m, k, l, r, op, x, y;
int f[N][N];
bool flag;
int p, maxi, sum;
void solve() {
while (cin >> n >> m) {
for (int i = 1; i <= n; i++) {
p = 1, maxi = 0, sum = 0;
for (int j = 1; j <= m; j++) {
cin >> f[i][j];
sum += f[i][j];
if (f[i][j] > maxi) {
maxi = f[i][j];
p = j;
}
}
f[i][p] = sum;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << f[i][j] << " ";
}
cout << "\n";
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}