题解 | #矩阵转置#
矩阵转置
https://www.nowcoder.com/practice/351b3d03e410496ab5a407b7ca3fd841
#include <iostream>
using namespace std;
int main() {
int a, b;
int a1[11][11],b1[11][11];
while (cin >> a >> b) { // 注意 while 处理多个 case
for(int i=0;i<a;i++)
{
for (int j=0; j<b; j++)
{
cin>>a1[i][j];
}
}
for(int i=0;i<b;i++)
{
for (int j=0; j<a; j++)
{
b1[i][j]=a1[j][i];
}
}
for(int i=0;i<b;i++)
{
for (int j=0; j<a; j++)
{
cout<<b1[i][j]<<" ";
}
cout<<endl;
}
}
}
// 64 位输出请用 printf("%lld")
要先想想这个转置矩阵之间的关系 其实就是a[i][j]=b[j][i]
查看17道真题和解析
