题目描述
矩阵的转置:
A: B:
1 2 3 转置为 1 4 7 10
4 5 6 2 5 8 11
7 8 9 3 6 9 12
10 11 12
输入
输入n,m
输入一个n*m的矩阵
输出
输出转置后的矩阵
样例输入 复制
4 3 1 2 3 4 5 6 7 8 9 10 11 12
样例输出 复制
1 4 7 10 2 5 8 11 3 6 9 12
代码:
#include<bits/stdc++.h>
using namespace std;
int a[1001][1001],n,m;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
for(int j=1;j<=m;j++)
{
for(int i=1;i<=n;i++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}