题解 | 矩阵转置
矩阵转置
https://www.nowcoder.com/practice/351b3d03e410496ab5a407b7ca3fd841
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> shuzu(n, vector<int> (m));
vector<vector<int>> b(m, vector<int> (n));
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> shuzu[i][j];
b[j][i] = shuzu[i][j];
}
}
for (int i = 0; i < m; i++){
for (int j = 0; j < n; j++){
cout << b[i][j] << " ";
}
cout << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")